How to color input border bottom using CSS

我怕爱的太早我们不能终老 提交于 2019-12-25 08:58:08

问题


I need to color a input border bottom when the input is not focus. This is my html code:

<input type="number" id="nc" name="days" class="numero" placeholder="" min="0"><br />

This is my css code:

.numero {
    border-bottom-color: red;
}

But it doesn't work. Anyone can help?


回答1:


The border is red in your example:

.numero {
  border-bottom: 1px solid #F00;
}
<input type="number" id="nc" name="days" class="numero" placeholder="" min="0"><br />

Simply use the shorthand to add a style, size and color and it works.

Now, in order to remove this when it is focused:

.numero:not(:focus) {
  border-bottom: 1px solid #F00;
}
<input type="number" id="nc" name="days" class="numero" placeholder="" min="0"><br />

We use the :not() functionality with the :focus to check if the element in question is not focused.




回答2:


use this code

input.numero {
 border-bottom-color:red;
}

Working Fiddle




回答3:


Add some border style:

.numero{
  border: 1px, solid;
  border-bottom-color: red;
}



回答4:


You should define the border thickness in the css. You can write that like this

.numero {
    border-bottom:1px solid red;
}

And on focus if you want another color you can like this

.numero:focus {
    border-bottom:1px solid transparent;
}

You can change the value of transparent to any other color of your preference.




回答5:


.numero {
  border-bottom: 2px solid cyan;
}
<input type="number" id="nc" name="days" class="numero" placeholder="" min="0"><br />

for any query please comment. All the best




回答6:


.numero {
    border-bottom:1px solid red;
}


来源:https://stackoverflow.com/questions/46360881/how-to-color-input-border-bottom-using-css

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