如何在输入表单中添加静态文本

新手上路,请多包涵

如何将此静态文本放入输入表单中?

它一直在那里。

在此处输入图像描述

这是我的代码:

 <label for="subdomain">Subdomain:</label>
<input type="text" placeholder="ExampleDomain" id="subdomain"/>

原文由 Davor Budimir 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 470
2 个回答

HTML

 <label for="subdomain">Subdomain:</label>
<input type="text" placeholder="ExampleDomain" id="subdomain" />
<input type="text" id="subdomaintwo" value=".domain.com" disabled/>

CSS

 input[type="text"]#subdomaintwo{
    -webkit-appearance: none!important;
    color: red;
    text-align: right;
    width: 75px;
    border: 1px solid gray;
    border-left: 0px;
    margin: 0 0 0 -7px;
    background: white;
}
input[type="text"]#subdomain{
    -webkit-appearance: none!important;
    border: 1px solid gray;
    border-right: 0px;
    outline: none;
}

JS Fiddle为此

原文由 alessandrio 发布,翻译遵循 CC BY-SA 4.0 许可协议

您可以使用以下方法实现此目的:

  • <input> 放在 <label>position:relative
  • <label> 一个 ::after 伪元素 position:absolute
  • box-sizing<input> 设置为 border-box
  • 给出 <input> a padding-right 等于 ::after 伪元素的宽度

工作示例:

 label, input {
    position: relative;
    display: block;
    padding-right: 76px;
    width: 174px;
    box-sizing: border-box;
}

label::after {
    content: '.' attr(data-domain);
    position: absolute;
    top: 4px;
    left: 96px;
    font-family: arial, helvetica, sans-serif;
    font-size: 12px;
    display: block;
    color: rgba(0, 0, 0, 0.6);
    font-weight: bold;
}
 <label data-domain="domain.com">
<input type="text" placeholder="exampledomain" />
<label>

原文由 Rounin - Standing with Ukraine 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题