html - How to make text of nested item become red when mouse over? -
a:hover, li:hover { color: red; }
<ol> <a href="#"><li>main1</li></a> <a href="#"><li>main2</li> <a href="#"><li>main3 <ol> <a href="#"><li>sub1</li></a> <a href="#"><li>sub2</li></a> <a href="#"><li>sub3</li></a> </ol> </li></a> <a href="#"><li>main4</li></a> <a href="#"><li>main5</li></a> <a href="#"><li>main6</li></a> </ol>
i have nested order list. when mouse hover on each item , text become red. however, when mouse on sub item, number of main become red.
(example, when hover on sub1 number "3" of main3 become red)
how fix it? doing wrong?
you have few issues in code.
1: need close anchor tag around main2, otherwise technically entire rest of page part of link.
2: wrong, i'm pretty sure you're not allowed have child of ol or ul except li (so should <li><a>linked list item</a></li>
instead of <a><li>linked list item</li></a>
). (see accepted answer question on nested lists: proper way make html nested list?)
3: css rule says "if hover on list items make them red. if hover on anchors make them red." since sub list nested within list item in main list, when hover on sub list, technically hovering on 3rd list item in main list (see fiddle made demonstrate mean: http://jsfiddle.net/pah3gstn/2/).
that means if click on 1 of sub links how had anchor tags set before, click through link main3 supposed go to.
4: once fix structure of list (issues 1, 2, & 3) can change css a:hover {color:red;}
, because need change color on specific link you're hovering over.
i fixed of issues can see working here : http://jsfiddle.net/pah3gstn/
Comments
Post a Comment