I am looking for a possible way, solely using CSS that could allow one to increment a CSS counter for every line of text within a DOM element.
This question is similar, but not the same as this SO question.
Using this as an example:
<p>Here is a basic "hello world" program, written in Rust:</p>
<code>
fn main() {
println!("Hello, world!");
}
</code>
With white space preservation:
code {
white-space: pre-wrap;
}
I am looking for a way that I could make this appear with a line number before each line of text (or just before each newline character).
1. | fn main() {
2. | println!("Hello, world!");
3. | }
I was thinking that I could use pseudo-selectors, CSS counters, contents:
, and a few other ideas, to make it happen, but I have no way to select each line.
I know that there are the ::first-letter
and ::first-line
pseudo-elements, but after looking everywhere I could find no mention of something like an nth-line()
, or ::line
selectors.
Does anyone know of any obscure CSS trick that could make this possible?