小编典典

CSS:not(:last-child):选择器之后

css

我有一个元素列表,其样式如下:

ul {

    list-style-type: none;

    text-align: center;

}



li {

    display: inline;

}



li:not(:last-child):after {

    content:' |';

}


<ul>

    <li>One</li>

    <li>Two</li>

    <li>Three</li>

    <li>Four</li>

    <li>Five</li>

</ul>

输出One | Two | Three | Four | Five |代替One | Two | Three | Four | Five

有谁知道如何使用CSS选择除最后一个元素以外的所有元素?

您可以在此处查看:not()选择器的定义


阅读 6888

收藏
2020-05-16

共1个答案

小编典典

如果不是选择器有问题,则可以设置所有选择器并覆盖最后一个选择器

li:after
{
  content: ' |';
}
li:last-child:after
{
  content: '';
}

或者如果您可以使用之前,则不需要最后一个孩子

li+li:before
{
  content: '| ';
}
2020-05-16