![](/img/trans.png)
[英]CSS Why is the last li not being targeted by li:nth-child(odd) or li:nth-child(even)?
[英]how to style first element of every even li with css only if possible`` ul li:nth-child(odd)>a{..}``
我有這樣的 HTML 代碼
<ul>
<li>
<a>first</a>
<ul>
<li><a>sub-1</a></li>
<li><a>sub-2</a></li>
</ul>
</li>
<li><a>..</a></li>
</ul>
我只想為第一個'ul'的奇數'li'的每個'a'設置樣式我正在這樣做
ul>li:nth-child(odd)>a{background:#000}
這里有什么錯誤??? 因為它也采用子'ul'的'a'
測試父是否不是li
:not(li) > ul > li:nth-child(odd) > a { background: red }
<ul> <li> <a>first</a> <ul> <li><a>sub-1</a></li> <li><a>sub-2</a></li> </ul> </li> <li><a>..</a></li> </ul>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.