我是一个有用的助手,可以为您进行文本翻译。
我正在玩伪元素样式,并遇到了令我困惑的行为。
考虑以下CSS和HTML:
HTML:
在Chrome中,行为如下:即使它不是p的内容,::before内容的第一个字母仍然被着色为红色,并且::before样式没有将颜色覆盖为蓝色。
此外,当::before内容中没有字母并且我输入&或*时,所有第一行都变成绿色,并且没有应用::first-letter和::before样式。
在Firefox中,提供的代码的结果将如下所示:
我正在Ubuntu 17.04下使用最新的浏览器版本。
那么有人能解释一下为什么其他伪元素选择器选择了::before内容并应用了它们的样式,而自己的::before样式却不能覆盖它们,即使它们是“后来”的样式吗?
我正在玩伪元素样式,并遇到了令我困惑的行为。
考虑以下CSS和HTML:
HTML:
<p>
Note: As a rule, double colons (::) should be used instead of a single colon (:). This distinguishes pseudo-classes from pseudo-elements. However, since this distinction was not present in older versions of the W3C spec, most browsers support both syntaxes for the sake of compatibility. Note that ::selection must always start with double colons ::.
</p>
和样式
p::first-letter {
font-size: 20px;
color: red;
}
p::first-line {
font-variant: small-caps;
color: green;
}
p::before {
content: 'Start';
color: blue;
}
在Chrome中,行为如下:即使它不是p的内容,::before内容的第一个字母仍然被着色为红色,并且::before样式没有将颜色覆盖为蓝色。
![enter image description here](https://istack.dev59.com/0Swol.webp)
在Firefox中,提供的代码的结果将如下所示:
![enter image description here](https://istack.dev59.com/gsmMF.webp)
那么有人能解释一下为什么其他伪元素选择器选择了::before内容并应用了它们的样式,而自己的::before样式却不能覆盖它们,即使它们是“后来”的样式吗?