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 | 而不是One | Two | Three | Four | Five One | Two | Three | Four | Five html

任何人都知道如何选择CSS除了最后一个元素? 浏览器

您能够在此处查看 :not()选择器的定义 ide


#1楼

每件事彷佛都是正确的 您可能但愿使用如下css选择器而不是您使用的css选择器。 工具

ul > li:not(:last-child):after

#2楼

使用CSS的示例 spa

ul li:not(:last-child){
        border-right: 1px solid rgba(153, 151, 151, 0.75);
    }

#3楼

你能够试试这个,我知道不是你要找的答案,但概念是同样的。 code

在哪里为全部孩子设置样式,而后从最后一个孩子中删除它。 orm

代码片断 htm

li
  margin-right: 10px

  &:last-child
    margin-right: 0

图片 图片

在此输入图像描述


#4楼

对我来讲它工做得很好

&:not(:last-child){
            text-transform: uppercase;
        }

#5楼

您编写的示例在Chrome 11中彻底适用于我。 也许你的浏览器不支持:not()选择器?

您可能须要使用JavaScript或相似工具来完成此跨浏览器。 jQuery在其选择器API中实现:not()

相关文章
相关标签/搜索