Can you please take a look at this link and let me know why I am not able to change the background color of the li on hover?
<ul class="inline">
<li>1</li>
<li>2</li>
<li>3</li>
<li>3</li>
<li>3</li>
</ul>
Css:
.inline li{
width:18% !important;
background:#FFF !important;
}
.inline li: hover{
background:#A5A5A5 !important;
}
Changing link color on hover using CSS To change the color of your link on hover, use the :hover pseudo property on the link's class and give it a different color.
Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.
If you want to change the link color when moving the mouse over a link, you only need the A:hover line. hover - The hover option is the color that the text changes to when the mouse is over the link. In this example, the link changes to a blue color when a mouse cursor is hovering over a link.
The :hover CSS pseudo-class matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer).
You have an extra space before hover.
.inline li:hover{
background:#A5A5A5 !important;
}
The space between li
and :hover
is valid CSS, but not in this case. Using li :hover
will apply styles when you hover over any descendant of the li
. What you are using is invalid CSS. You can't have a colon between an element and a pseudo-class. So by using li:hover
, you are specifiying the styles when the li
is being hovered over.
I would also recommend that you not use !important
, because it can cause some problems later down the road. Use more specific DOM selectors, like ul.inline li:hover
.
Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With