据我所知,只有使用纯CSS,通过:first-line伪元素来做到这一点
概念
默认情况下,为每个元素添加“视觉指示”。
选择每个:first-line元素以重置样式。
<code>
<div class="line">Too much code at one line. Learn to write shorter lines!</div>
<div class="line">Lonely line.</div>
...
</code>
Run Code Online (Sandbox Code Playgroud)
CSS:
code {display: block; width: 150px;} /* <-- Not interesting, just for testing*/
code .line { color: red; /* Visual indication */ }
code .line:first-line { color: #000; /* Default color */ }
Run Code Online (Sandbox Code Playgroud)
该演示呈现为(默认为黑色,红色为“视觉指示”):
