Underline fixed in input text

狂风中的少年 提交于 2020-01-02 13:09:16

问题


I'm trying to fixed the underline in all input text type, but without success.

Example:

My code:

input {
  width: 100%;
  background-color: #fcfcfc;
  border: 0;
  padding: 10px;
}
<div class="col-lg-6 col-md-6 col-xs-12 col-sm-12">
  <label for="endereco">Endereço:</label>
  <input class="" id="endereco" type="text" tabindex="2" minlength="5" required>
</div>

回答1:


Use linear-gradient as background to create a line and you can easily control its size and position like this:

input {
  width: 300px;
  background: linear-gradient(to right, #000, #000) 5px calc(100% - 5px)/calc(100% - 10px) 2px no-repeat;
  /* <5px calc(100% - 5px)> : position of the gradient [5px from left and 5px from bottom  */
  /* <calc(100% - 10px) 2px> : size of the gradient [width:100%-10px height:2px] */
  background-color: #fcfcfc;
  border: 1px solid;
  padding: 10px;
}
<input class="" id="endereco" type="text" tabindex="2" minlength="5" required>

You can also use and easier syntax:

input {
  width: 300px;
  background-image: linear-gradient(to right, #000, #000);
  background-position: 5px calc(100% - 5px);
  background-size: calc(100% - 10px) 2px;
  background-repeat: no-repeat;
  background-color: #fcfcfc;
  border: 1px solid;
  padding: 10px;
}
<input class="" id="endereco" type="text" tabindex="2" minlength="5" required>



回答2:


Add a border to the bottom of the input?

input {
  width: 100%;
  background-color: #fcfcfc;
  border: 0;
  border-bottom: 2px solid lightgrey;
  padding: 10px;
}
<div class="col-lg-6 col-md-6 col-xs-12 col-sm-12">
  <label for="endereco">Endereço:</label>
  <input class="" id="endereco" type="text" tabindex="2" minlength="5" required>
</div>


来源:https://stackoverflow.com/questions/48270694/underline-fixed-in-input-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!