在 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 為文本添加下劃線、上劃線和刪除線?的詳細內容,更多請關注www.92cms.cn其它相關文章!