CSS :not(:last-child):after 选择器 [英] CSS :not(:last-child):after selector

查看:81
本文介绍了CSS :not(:last-child):after 选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a list of elements, which are styled like this:

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>

输出 一个 |二 |三 |四 |五个 | 而不是 一个 |二 |三 |四 |五

有人知道如何通过 CSS 选择除最后一个元素之外的所有元素吗?

Anyone know how to CSS select all but the last element?

可以看到:not()选择器的定义这里

推荐答案

如果是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):after 选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆