Css儿童的before&;之后
在ul中,我有6个lis,我想取最后5个lis:之前和之后 我怎样才能让孩子们知道(除了第一个): 我试过了,但没有成功:Css儿童的before&;之后,css,css-selectors,html-lists,Css,Css Selectors,Html Lists,在ul中,我有6个lis,我想取最后5个lis:之前和之后 我怎样才能让孩子们知道(除了第一个): 我试过了,但没有成功: nav li:nth-child(n+5) a:before, nav li:nth-child(n+5) a:after { content:none; } 快速更新以适应: nav ul li:nth-child(5) a:before, nav ul li:nth-child(5) a:after { content:.; } 快速更新以适应:
nav li:nth-child(n+5) a:before, nav li:nth-child(n+5) a:after {
content:none;
}
快速更新以适应:
nav ul li:nth-child(5) a:before,
nav ul li:nth-child(5) a:after {
content:.;
}
快速更新以适应:
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 li:not(:first-child) a::before,
nav li:not(:first-child) a::after {
/* your styles here */
}
或
您可以使用css,如下所示:
nav ul li:nth-child(5) a:before,
nav ul li:nth-child(5) a:after {
content:.;
}
您可以使用css,如下所示:
nav ul li:nth-child(5) a:before,
nav ul li:nth-child(5) a:after {
content:.;
}
有两种方法可以实现这一点。一种方法是简单地将样式应用于以下对象:
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个最后一个孩子。有两种方法可以实现这一点。一种方法是简单地将样式应用于以下对象:
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最后一个子元素。我不清楚您要选择的是最后5个元素还是除最后5个之外的所有元素。最后5个,所以除第一个之外的所有元素我不清楚您要选择的是最后5个元素还是除最后5个之外的所有元素。最后5个,因此,除第一个问题外,其他所有问题都可以从理论上回答这个问题,在这里包括答案的基本部分,并提供链接供参考。如果链接页面发生变化,则只有链接的答案可能无效,而这可能从理论上回答问题,包括此处答案的基本部分,并提供链接供参考。如果链接页面发生更改,则仅链接的答案可能无效