如何移除最后一个.note-right small的::after伪元素双换行?
问题描述
我有一组笔记,通过为.note-right small元素添加::after伪元素实现末尾双换行,代码如下:
.note-right small::after { content: "\a\a"; white-space: pre }
现在我希望最后一个笔记末尾无换行,尝试使用以下代码但无效:
.note-right small:last-child { content: none; }
请问我遗漏了什么?
解决方法
你写错了选择器——你当前的代码是针对最后一个small元素本身设置content,但content属性仅对伪元素生效,且我们要修改的是small的::after伪元素样式。
正确的写法是给最后一个small的::after伪元素设置样式:
.note-right small::after { content: "\a\a"; white-space: pre; } .note-right small:last-child::after { content: none; }
这样就能取消最后一个.note-right small元素的末尾双换行了。
内容的提问来源于stack exchange,提问作者rocco
相关产品推荐
相关产品推荐

