你好
我尝试对使用 :after
添加的内容进行样式设置,color: ;
被覆盖,但 text-decoration: ;
没有'不工作。
code.html
<html>
<head>
<style>
.separate-hyphen *:not(:last-child):after {
content: " -\00a0";
text-decoration: none;
color: red;
}
</style>
</head>
<body>
<div class="separate-hyphen">
<a href="link1.extension">Link 1</a>
<a href="link2.extension">Link 2</a>
</div>
</body>
</html>
结果 (这是一张图像)
最佳答案
因为伪元素 :after
渲染在元素的内部,而不是外部,所以它的样式当然不会影响外部容器样式:
+--------------------+
| +--------+ |
| Content | :after | |
| +--------+ |
+--------------------+
你需要找到另一种方法。也许可以通过绝对定位在视觉上将 :after
移动到其容器之外:
.separate-hyphen *:not(:last-child) {
margin-right: 10px;
}
.separate-hyphen *:not(:last-child):after {
content: " -\00a0";
text-decoration: none;
color: red;
position: absolute;
padding: 0 5px;
}
<div class="separate-hyphen">
<a href="link1.extension">Link 1</a>
<a href="link2.extension">Link 2</a>
</div>
关于html - 某些样式不适用于 :after,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32797304/