CSS - 偽元素 - ::first-line



::first-line 偽元素用於對塊級元素的第一行應用特殊效果或樣式。此偽元素對內聯元素無效。它僅適用於塊級元素。

受偽元素::first-line影響的文字範圍取決於視口寬度、行長、字型大小、字母間距、字間距等因素。

只有少量 CSS 屬性可以與::first-line偽元素一起使用,如下所示:

語法

selector::first-line {
   /* ... */
}

CSS ::first-line 示例

以下是一個展示::first-line偽元素簡單用法的示例:

<html>
<head>
<style>
   p::first-line {
      color: black;
      font-size: 2em;
      text-decoration-color: rgb(4, 65, 65);
      text-decoration-line: line-through;
   }
</style>
</head>
<body>
   <p>First line is affected by the pseudo-element.<br />
      Second line has no effect.
   </p>
   <span>Even to an inline element there is no effect.</span>
</body>
</html>
廣告

© . All rights reserved.