我想将<a>
元素第一次出现在此列表中,first-child似乎不起作用,因为它选择了所有子元素<a>
。有任何想法吗?
<li class="cat-item cat-item-1 current-cat">
<a title="View all posts filed under Basket" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=1">Basket</a>
<ul class="children">
<li class="cat-item cat-item-19">
<a title="View all posts filed under Article List" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=19">Article List</a>
<ul class="children">
<li class="cat-item cat-item-20">
<a title="View all posts filed under Mobile" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=20">Mobile</a>
<ul class="children">
<li class="cat-item cat-item-21">
<a title="View all posts filed under Current" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=21">Current</a>
</li>
</ul>
</li>
<li class="cat-item cat-item-22">
<a title="View all posts filed under Desktop" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=22">Desktop</a>
<ul class="children">
<li class="cat-item cat-item-23">
<a title="View all posts filed under Current" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=23">Current</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
最佳答案
您需要定位第一个li,然后将其定位为链接
ul li:first-child a {
/* your styles here */
}
很难具体说明,但是如果您指的是
children
ul,则可以做到 ul.children > li:first-child a {
/*your styles here */
}
如果你是这个意思
<li class="cat-item cat-item-1 current-cat">
<a title="View all posts filed under Basket" href="http://machinas.com/wip/esprit/wiki/wordpress/?cat=1">Basket</a>
CSS将是
li.cat-item.cat-item-1.current-cat > a {
/*styles */
}
关于css - 目标元素css的首次出现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24953492/