选择子标签:元素之后,最后一个除外

Gab*_*iel -1 css

我有一个有角度的应用程序,在其中有自定义组件(标签)div

<div class="parent">
    <custom-1></custom-1>
    <custom-2></custom-2>
    <custom-3></custom-3>
    <custom-4></custom-4>
</div>
Run Code Online (Sandbox Code Playgroud)

我想选择所有子标签的:after内部.parent,因此我可以在组件之间创建分隔线,除了最后一个之后。

目前,我只选择了所有:

.parent > *:after {
    content: "";
    height: 60%;
    width: 1px;
    background-color: black;
    position: absolute;
    right: 0;
    top: 5px;
}
Run Code Online (Sandbox Code Playgroud)

看来,这*是在忽略:last-of-type,因为如果我这样使用它:.parent > *:last-of-type:after,它什么也不会选择。

car*_*mba 5

不确定您的代码,但您甚至可能不需要将其*组合在一起:last-child:after就像这样

.parent > :after {
    content: "";
    display: block;
    width: 20px;
    height: 20px;
    margin: 5px;
    background-color: orange;
}


.parent > :last-child:after {
    background-color: green;
}
Run Code Online (Sandbox Code Playgroud)
<div class="parent">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>
Run Code Online (Sandbox Code Playgroud)

使用时*,您需要选择元素内的所有元素.parent。因此,如果您的子元素中.parent有更多子元素

最后一类的不会起作用,因为:after是一个伪元素,:last-of-type将检查元素的类型(如divspanp)选择