开发者

Can I specify styling for specific lines in css?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜