CSS 嵌套 :after of :last-child with LESS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11969075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 04:48:17  来源:igfitidea点击:

Nesting :after of :last-child with LESS

cssless

提问by Staffan Estberg

Using LESS I need to remove an :after property within an element's :last-child.

使用 LESS 我需要删除元素的 :last-child 中的 :after 属性。

li {
    &:after {
        content: '/';
    }
    &:last-child {
        &:after {
            content: '';
        }
    }
}

This is obviously not correct nesting - what am I missing?

这显然不是正确的嵌套 - 我错过了什么?

回答by BoltClock

It looks correct to me, but if it's not working then try not nesting that second :after:

它对我来说看起来是正确的,但如果它不起作用,那么尝试不要嵌套第二个:after

li {
    &:after {
        content: '/';
    }
    &:last-child:after {
        content: '';
    }
}

If you mean that the :afterpseudo-element still displays for the last child, then you'll definitely want to change content: '';to content: none;instead. An empty string will still cause an empty box to be generated, while nonegenerates nobox.

如果你的意思是,:after伪元素仍然显示过去的孩子,那么你肯定会想改变content: '';,以content: none;代替。空字符串仍然会导致生成一个空框,而不会none生成任何框。

回答by Carlos

You can use also:

您还可以使用:

li {
&:not(:last-child):after {
    content: " | ";

  }
}