如下代码所示,要对class值为children的第一个和最后一个背景色单独设置,为什么first-of-type有效果,last-of-type不起作用呢?
<span class="parent">
<span class="children">1</span>
<span class="children">2</span>
<span class="children">3</span>
<span class="children">4</span>
<span class="children">5</span>
<span class="special">就是不一样</span>
</span>
.children{
display:inline-block;
width:50px;
height:50px;
background:gray;
&:first-of-type{
background:pink;
}
&:last-of-type {
background:yellow;
}
}
看了楼下的答案我发现我错了。哈哈哈哈
.children
和:last-of-type
需要同时满足。满足:
.children
满足:
:last-of-type
满足
:last-child
满足
:nth-last-of-type(1)
问题常出现在 list 组件中,后面跟了一个加载更多,导致样式无法生效。解决办法就是给 children 做一个父级。。