So I am making a website for a school project and I have multiple inputs on that website that have the same class (the class is called "in") because I want to apply the same styles to all of them but I want the border-color to change while the input is selected (:focus), but instead the styles that I chose, some other styles are applying which set the border width to 2px and the color to black, which I don’t want.
here’s the css code that can affect the ".in" class’s style:
.in:focus, .in:hover, .in:active{
border-width: 1px;
border-color: #002f86 !important;
}
.in {
display: block;
margin-top: 20px;
font-family: roboto;
width:178px;
border-style: solid;
border-width: 1px;
border-color: rgba(254,196,58,255);
height: 20px;
font-size: 15px;
border-radius: 10px;
padding-left: 6px;
}
I tried this:
in:focus, .in:hover{
border-width: 1px;
border-color: #002f86 !important;
}
and I expected that while hovering or focusing, the border styles change. The hover part works just fine but the focus isn’t working, but instead it’s setting border width to 2px and color to black
2
Answers
I would avoid messing with the focus default styles. You could use outline instead?
Browsers have some default styles for
input:focus
.I think you’re misinterpreting
outline
asborder
.You can remove browser’s default outline by doing something like this:
So the final code will look like this:
But be aware that you should never completely remove focus styles. You should always have a distinct styles for
:focus
in order to respect accessibility concerns.For more information please refer to this article on MDN website.