<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
p:before {
content:"Former - ";
color:red;
font-family:"Tahoma" ,Times New Roman;
font-size:70%;
}
p.normal:first-letter {
font-size:40px;
color:blue;
}
</style>
</head>
<body>
<p class="normal">First character of this paragraph will
be normal and will have font size 40px;</p>
</body>
</html>
这里,
:before
伪元素中的内容是红色显示的,但我还想将 "First character of this paragraph" 中的字符 "F" 设为蓝色。但实际上,我看到的是 "Former - " 中的 "F" 是蓝色的。我想要的是将
:before
和 .normal
的第一个字母(在 :before
内容之后)应用于同一段落。这是否可能?如果是,应该怎么做?
:before
更改为:after
,并使用绝对定位在容器之前视觉上放置它,但在语义上仍然在其后(从而允许::first-child
起作用);这不是一个足够好的解决方案,无法发布为答案,但在我看来它有其优点。 - user719662