开发者

Can I specify styling for specific lines in css?

开发者 https://www.devze.com 2023-03-24 09:00 出处:网络
Is there any way to apply css formatting to just the first (or nth) line of text in CSS? Suppose I have:

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 dis开发者_如何学Goplayed as:

This is a line of text

on my web page

Is there a way to specify, a priori, separate formatting for the first and second lines without knowing where the line break will occur?


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;
}


Use the :first-line selector (CSS2) or ::first-line selector (CSS3).

h2:first-line {
  font-weight: bold;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消