在一个ul中,我有6个列表,我想取最后5个列表:在
之前和之后如何获得this的子元素(除了第一个):
nav li a:before, nav li a:after {
}
我试过这个,但没有工作:
nav li:nth-child(n+5) a:before, nav li:nth-child(n+5) a:after {
content:none;
}
有两种方法。一种方法是简单地将样式应用于以下内容:
nav li a:before, nav li a:after {
}
然后重写第一个元素的样式
nav li:first-child a:before, nav li:first-child a:after {
}
或者,您可以使用:nth-last-child()选择器来选择您需要的最后5个元素:
nav li:nth-last-child(-n+5) a:before, nav li:nth-last-child(-n+5) a:after {
}
唯一的问题是IE8不支持:n -last-child
你可以使用如下所示的CSS:
nav ul li:nth-child(5) a:before,
nav ul li:nth-child(5) a:after {
content:.;
}
你可以这样做:
nav li:not(:first-child) a::before,
nav li:not(:first-child) a::after {
/* your styles here */
}
或
nav ul li:nth-last-child(-n+5) {
/* your styles here */
}
快速更新以适应:
nav ul li:nth-child(5) a:before,
nav ul li:nth-child(5) a:after {
content:.;
}