Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text and link-color inside list-element on hover

I've got an ordered list like this

<ol class="tracklist">
    <li>
        <a href="www.html">LINK</a>
        <span>some text</span>
     </li>
</ol>

I want to change the color of the list-numbers, link and span upon hovering on the list element.

Therefore I have this in css:

ol.tracklist li:hover {
    background-color: #D21600;
    color: #FFFFFF;
}

It only changes the list-numbers and span's color though.

What can I do about this (without using JS).

like image 663
Hedge Avatar asked Sep 13 '25 02:09

Hedge


2 Answers

Anchor tags don't inherit attributes such as color when the href attribute is present.

You can use multiple selectors to apply the same style, separate them with a comma.

ol.tracklist li:hover, ol.tracklist li:hover a {
    background-color: #D21600;
    color: #FFFFFF;
}
like image 179
Town Avatar answered Sep 14 '25 16:09

Town


It looks like you have some extra s's in you styles

Change ol.strackslist to ol.tracklist in your css and it works.

You also need to add this for the link to change color:

ol.tracklist li:hover a, ol.tracklist li a:hover {
    color:#fff;
}

http://jsfiddle.net/jasongennaro/mje9t/1/

like image 44
Jason Gennaro Avatar answered Sep 14 '25 16:09

Jason Gennaro