CSS:not(:last-child):后选择器 [英] CSS :not(:last-child):after selector
本文介绍了CSS:not(:last-child):后选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个元素列表:
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
</ul>
并且样式如下:
ul {
list-style-type: none;
text-align: center;
}
li {
display: inline;
}
li:not(:last-child):after {
content:' |';
}
输出二|三|四| Five |
而不是 One |二|三|四|五
Outputs One | Two | Three | Four | Five |
instead of One | Two | Three | Four | Five
任何人都知道如何选择除最后一个元素之外的所有元素。
Anyone know how to CSS select all but the last element?
您可以查看:not()
选择器的定义这里
You can see the definition of the :not()
selector here
推荐答案
如果这是not选择器的一个问题,你可以设置所有的和覆盖最后一个
If it's a problem with the not selector, you can set all of them and override the last one
li:after
{
content: ' |';
}
li:last-child:after
{
content: '';
}
或者如果以前可以使用,则不需要last-child
or if you can use before, no need for last-child
li+li:before
{
content: '| ';
}
这篇关于CSS:not(:last-child):后选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文