Today I realized there is still so much to learn about CSS. How is it possible that the CSS style below produces that outcome?
Stylesheet:
li.item a:first-child {color: red}
HTML List:
<ul class="mylist">
<li class="item"><a href="#">item 1</a>
<ul>
<li class"child"><a href="#">child item 1</li>
<li class="child"><a href="#">child item 1</li>
</ul>
</li>
</ul>
Despite the fact that the <a>
inside <li class="child">
is not the a:first-child
of <li class="item">
, it still appears red. Why is that so? Is there another way to only target the first <a>
within <li class="item">
without modifying the HTML?
How do I specifically select only the first <a>
within li.item?