How to color input border bottom using CSS

2019-08-18 16:47发布

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?

标签: html css css3
6条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-18 17:12

use this code

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

Working Fiddle

查看更多
Animai°情兽
3楼-- · 2019-08-18 17:26

Add some border style:

.numero{
  border: 1px, solid;
  border-bottom-color: red;
}
查看更多
甜甜的少女心
4楼-- · 2019-08-18 17:33

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.

查看更多
祖国的老花朵
5楼-- · 2019-08-18 17:34

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.

查看更多
做自己的国王
6楼-- · 2019-08-18 17:36
.numero {
    border-bottom:1px solid red;
}
查看更多
ら.Afraid
7楼-- · 2019-08-18 17:38

.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

查看更多
登录 后发表回答