Reputation: 33
Is there any way to apply css formatting to just the first (or nth) line of text in CSS? Suppose I have:
<h2>This is a line of text on my web page</h2>
That gets displayed as:
Is there a way to specify, a priori, separate formatting for the first and second lines without knowing where the line break will occur?
Upvotes: 3
Views: 2535
Reputation: 4258
Use the :first-line selector (CSS2) or ::first-line selector (CSS3).
h2:first-line {
font-weight: bold;
}
Upvotes: 1
Reputation: 724342
There is only the :first-line
pseudo-element; there isn't any for the second, third, fourth, ... nth lines.
h2 {
font-size: 2em;
color: blue;
}
h2:first-line {
color: red;
}
Upvotes: 4