text-decoration屬性用於對文本的內容進行“decorate”。它本質上是用不同種類的線條來裝飾文本。它是text-decoration-line(必填),text-decoration-color和text-decoration-style的簡寫屬性。句法:
text-decoration:text-decoration-line text-decoration-style text-decoration-color|initial|inherit;
屬性值:
- text-decoration-line:指定使用的裝飾類型(例如,下劃線,上劃線等)。
用法:
text-decoration:text-decoration-line;
例:
<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>text-decoration</title> <style> h1 { color:green; } body { text-align:center; } ul li { margin-top:15px; } #example1 { text-decoration:underline; } #example2 { text-decoration:line-through; } #example3 { text-decoration:overline; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2> text-decoration:text-decoration-line;</h2> <ul> <li id="example1">Welcome geeks!</li> <li id="example2">Welcome geeks!</li> <li id="example3">Welcome geeks!</li> </ul> </body> </html> </html>
輸出:
- text-decoration-style:指定使用的裝飾風格(例如,點綴,波浪形等)。
用法:text-decoration:text-decoration-line text-decoration-style;
例:
<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>text-decoration</title> <style> h1 { color:green; } body { text-align:center; } ul li { margin-top:15px; } #example1 { text-decoration:underline dotted; } #example2 { text-decoration:underline wavy; } #example3 { text-decoration:underline dashed; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2> text-decoration: text-decoration-line text-decoration-style; </h2> <ul> <li id="example1">Welcome geeks!</li> <li id="example2">Welcome geeks!</li> <li id="example3">Welcome geeks!</li> </ul> </body> </html>
輸出:
- text-decoration-color:指定裝飾的顏色。
用法:text-decoration:text-decoration-line text-decoration-color;
例:
<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>text-decoration</title> <style> h1 { color:green; } body { text-align:center; } ul li { margin-top:15px; } #example1 { text-decoration:underline wavy green; } #example2 { text-decoration:line-through red; } #example3 { text-decoration:overline blue; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2> text-decoration: text-decoration-line text-decoration-color; </h2> <ul> <li id="example1">Welcome geeks!</li> <li id="example2">Welcome geeks!</li> <li id="example3">Welcome geeks!</li> </ul> </body> </html>
輸出:
- initial:將屬性設置為其默認值。
用法:text-decoration:initial;
例:
<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>text-decoration</title> <style> h1 { color:green; } body { text-align:center; } #example1 { text-decoration:initial; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2> text-decoration:initial;</h2> <a href="#"> This is a link without text-decoration. </a> <br> <br> <a id="example1" href="#"> This is a link with text-decoration set to initial. </a> </body> </html>
輸出:
- inherit:它從其父元素繼承此屬性。
用法:text-decoration:inherit;
例:
<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>text-decoration</title> <style> h1 { color:green; } body { text-align:center; } #example1 { text-decoration:underline wavy green; } #example1child { text-decoration:inherit; font-weight:bold; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2> text-decoration:inherit;</h2> <p id="example1"> I am parent and <span id="example1child"> this my is child.</span> </p> </body> </html>
輸出:
支持的瀏覽器:text-decoration屬性支持的瀏覽器如下所示:
- 穀歌瀏覽器
- IE瀏覽器
- 火狐瀏覽器
- Opera
- 蘋果瀏覽器
相關用法
- HTML Style textDecoration用法及代碼示例
- CSS transition-property用法及代碼示例
- CSS nav-right用法及代碼示例
- CSS top屬性用法及代碼示例
- CSS all屬性用法及代碼示例
- CSS nav-down用法及代碼示例
- CSS nav-up用法及代碼示例
- CSS right屬性用法及代碼示例
- CSS will-change用法及代碼示例
- CSS clear屬性用法及代碼示例
- CSS bleed屬性用法及代碼示例
- CSS border-right用法及代碼示例
- CSS columns屬性用法及代碼示例
- CSS resize屬性用法及代碼示例
- CSS nav-left用法及代碼示例
注:本文由純淨天空篩選整理自Archana choudhary大神的英文原創作品 CSS | text-decoration Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。