首頁  >  文章  >  web前端  >  哪個屬性用於使用 CSS 為文字添加下劃線、上劃線和刪除線?

哪個屬性用於使用 CSS 為文字添加下劃線、上劃線和刪除線?

PHPz
PHPz轉載
2023-09-07 18:37:101690瀏覽

哪个属性用于使用 CSS 为文本添加下划线、上划线和删除线?

在 CSS 中,「text-decoration」屬性用於為文字新增底線、上劃線和刪除線。

在文字下劃線表示在文字下方畫一條線,在文字上劃線表示在文字上方畫一條線。刪除文字意味著在文字上畫一條線以顯示文字已被刪除。

在本教學中,我們將學習使用 text-decoration CSS 屬性的不同值來設定不同的文字樣式。

文法

text-decoration: style decoration color thickness;

  • Style—代表裝飾線的風格,如實線、點線、波浪線等

  • 裝飾-它可以用「底線」、「上劃線」和「穿過線」值來裝飾文字。

  • 顏色 - 設定裝飾線的顏色。

  • 粗細——用來設定裝飾線的粗細。

範例

在下面的範例中,我們使用「text-decoration」CSS 屬性來裝飾文字。我們設定了「實線」線條樣式、紅色「底線」裝飾和 5px 粗細,使用者可以在輸出中觀察到。

<html>
<head>
   <style>
      .text {
         font-size: 1.2rem;
         text-decoration: solid underline red 5px;
      }
   </style>
</head>
<body>
   <h3> Setting the underline to the text using the 'text-decoration' property in CSS </h3>
   <div class = "text">
      This is a text with an underline.
   </div>
</body>
</html>

範例

在下面的例子中,我們使用藍色上劃線的方式裝飾了文字。在輸出中,使用者可以觀察文字上方的藍線。

<html>
<head>
   <style>
      .text {
         font-size: 1.2rem;
         text-decoration: wavy overline blue 5px;
      }
   </style>
</head>
<body>
   <h3> Setting the <i> overline to the text </i> using the 'textdecoration' property in CSS </h3>
   <div class = "text">
      This is a text with an overline.
   </div>
</body>
</html>

範例

在此範例中,我們使用了「text-decoration」CSS 屬性和「line-through」值來刪除文字。在輸出中,使用者可以觀察文字上方的行。這樣,我們就可以在不刪除文字的情況下顯示文字中存在錯誤。

<html>
<head>
   <style>
      .text {
         font-size: 2rem;
         text-decoration: dotted line-through green 5px;
      }
   </style>
</head>
<body>
   <h3> Setting the <i> strickthrough to the text </i> using the 'textdecoration' property in CSS </h3>
   <div class = "text">
      This is a text with a strikethrough.
   </div>
</body>
</html>

範例

在此範例中,我們建立了三個具有不同文字的不同 div 元素。我們為每個 div 元素的文字使用了不同的裝飾風格。在輸出中,使用者可以觀察「底線」、「上劃線」和「穿線」文字裝飾樣式之間的差異。

<html>
<head>
   <style>
      .underline {
         color: grey;
         text-decoration: solid underline yellow 2px;
         font-size: 1.5rem;
      }
      .overline {
         text-decoration: solid overline yellow 3px;
         font-size: 1.5rem;
      }
      .strikethrough {
         text-decoration: solid line-through yellow 2px;
         font-size: 1.5rem;
      }
   </style>
</head>
<body>
   <h3> Setting the strikethrough, underline, and overline to the text using the 'text-decoration' property in CSS </h3>
   <div class = "underline"> underline </div>
   <div class = "overline"> overline </div>
   <div class = "strikethrough"> strike through </div>
</body>
</html>

結論

本教學教使用者如何使用「text-decoration」CSS 屬性來裝飾文字。使用者可以根據需要使用不同的值對文字進行不同的裝飾。

以上是哪個屬性用於使用 CSS 為文字添加下劃線、上劃線和刪除線?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除