gomezfx gomezfx - 4 months ago 7
HTML Question

Changing list item bullet/number color on hover

I'm trying to change a list item's color on hover, both the bullet/number and the text. I'm encountering a problem in Google Chrome where only the text is changing color. Am I missing something?

HTML:

<ul>
<li>test</li>
</ul>

<ol>
<li>test</li>
</ol>


CSS:

ol li:hover,
ul li:hover {
color: red;
}


JSFiddle:
https://jsfiddle.net/yf0yff1c/2/

Answer

You can have bullet in :before and than apply any valid CSS for that:

li {
  list-style: none;
}
li:before {
  content: "• ";
  color: black;
}
ol {
  counter-reset: item;
}
ol li {
  display: block;
}
ol li:before {
  content: counter(item)". ";
  counter-increment: item;
  color: black;
}
li:hover:before {
  color: red;
}
<ul>
  <li>HOVER ME</li>
</ul>

<ol>
  <li>HOVER ME</li>
</ol>