【问题标题】:Is it possible to put element inside input field?是否可以将元素放在输入字段中?
【发布时间】:2020-09-11 09:43:19
【问题描述】:

是否可以在输入字段内插入元素?这是一个例子:

我可以用什么来做到这一点?

我想知道表格,可以在输入字段中创建表格吗?

.box-login {
  width: 300px;
  height: auto;
  margin: 0 auto
}

.box-login .bots {
  width: 100%;
  height: auto;
  margin: 0;
  border-radius: 3px;
  -webkit-border-radius: 3px;
  -moz-border-radx-inpuius: 3px;
  -ms-border-radius: 3px;
  box-shadow: 0 0 4px rgba(0, 0, 0, .2);
  box-shadow: 0 0 4px rgba(0, 0, 0, .2);
  -webkit-box-shadow: 0 0 4px rgba(0, 0, 0, .2);
  -moz-box-shadow: 0 0 4px rgba(0, 0, 0, .2);
  -ms-box-shadow: 0 0 4px rgba(0, 0, 0, .2);
  background-color: #fff;
  position: relative
}

.box-login .box-inputs .line-input {
  width: 100%;
  height: 50px;
  padding-left: 0;
  position: relative;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  border-left: 0px;
  border-top: 0px;
  border-right: 0px;
}

.box-login .btn-login {
  width: 100%;
  margin: 0;
  height: 50px;
  color: #fff;
  border-radius: 0 0 3px 3px;
  -webkit-border-radius: 0 0 3px 3px;
  -moz-border-radius: 0 0 3px 3px;
  -ms-border-radius: 0 0 3px 3px;
  background-color: #009edb;
  border: none;
}
<form class="box-login">

  <div class="box-inputs">
    <label class="box-input" for="cpf"></label>
    <input class="line-input" id="cpf" type="text" placeholder="CPF">
  </div>

  <div class="box-inputs">
    <label for="box-input">
            <input class="line-input" id="password" type="password" placeholder="Senha">
            </label>

  </div>
  <div>
    <button class="btn-login">ENTRAR</button>
  </div>
</form>

【问题讨论】:

  • 使用伪元素或者看起来你的输入已经被包装了你可以使用
  • 谢谢@Darkrum,也许有帮助!能给我发个例子吗?
  • @epascarello 就像那张图片:prnt.sc/j7nki6,我正在寻找 ::before(CSS 伪元素)。对于测试,我在 CSS: line-input::before { content: url("loading.gif"); } 但什么也没发生

标签: javascript html css


【解决方案1】:

最好的方法是使用一个带有 position: absolute 的元素并将其放在输入字段的上方。试试这个代码。

<form class="box-login"  >

        <div class="box-inputs">
            <span class="icon"><img src="https://cdn3.iconfinder.com/data/icons/wpzoom-developer-icon-set/500/102-128.png"></span>
            <label class="box-input" for="cpf"></label>
            <input class="line-input" id="cpf" type="text" placeholder="CPF">
        </div>

        <div class="box-inputs">
            <span class="icon"><img src="https://cdn3.iconfinder.com/data/icons/wpzoom-developer-icon-set/500/102-128.png"></span>
            <label for="box-input">
            <input class="line-input" id="password" type="password" placeholder="Senha">
            </label>

        </div>
        <div>
            <button class="btn-login">ENTRAR</button>
</div>
</form>

.box-login{width:300px;height:auto;margin:0 auto}
 .box-login .bots{width:100%;height:auto;margin:0;border-radius:3px;-webkit-border-radius:3px;-moz-border-radx-inpuius:3px;-ms-border-radius:3px;box-shadow:0 0 4px rgba(0,0,0,.2);box-shadow:0 0 4px rgba(0,0,0,.2);-webkit-box-shadow:0 0 4px rgba(0,0,0,.2);-moz-box-shadow:0 0 4px rgba(0,0,0,.2);-ms-box-shadow:0 0 4px rgba(0,0,0,.2);background-color:#fff;position:relative}

 .box-login .box-inputs .line-input{width:100%;height:50px;padding-left:40px;position:relative;-webkit-box-sizing:border-box;box-sizing:border-box;
border-left:0px;
border-top: 0px;
border-right:0px;
 }

 .box-login .btn-login{width:100%;margin:0;height:50px;color:#fff;border-radius:0 0 3px 3px;-webkit-border-radius:0 0 3px 3px;-moz-border-radius:0 0 3px 3px;-ms-border-radius:0 0 3px 3px;background-color:#009edb;


    border: none;}

  .box-inputs {
    position: relative;
  }
  .box-inputs .icon {
    position: absolute;
    height: 24px;
    width: 24px;
    left: 10px;
    top: 10px;
    z-index: 2;
  }
  .box-inputs .icon img {
    width: 100%;
  }

【讨论】:

  • 一次一点,我会越来越好,感谢您分享您的知识
【解决方案2】:

不,您不能在 &lt;input&gt; element 中包含 any 元素。
它是一个empty (void) element,必须省略结束标签。
因此,您不能在其中包含任何元素。

【讨论】:

  • 感谢您的评论。你知道如何让它工作吗?我的意思是,如果输入的距离有点远以适合桌子?或者也许制作一个带有填充的 div?
  • 您可以使用marginpadding 来控制元素的对齐/偏移。但是您当然不能在 &lt;input&gt; 元素中包含任何其他元素。
  • 有没有一种实用的方法来建立一个表格只是为了在输入开始之前划定图标的使用?如果是边界0,如果是,你能帮我吗?建议的伪元素不起作用
猜你喜欢
  • 1970-01-01
  • 2021-11-18
  • 1970-01-01
  • 2015-09-01
  • 1970-01-01
  • 2014-01-31
  • 2013-05-24
  • 2017-12-17
  • 2022-11-03
相关资源
最近更新 更多