- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 塊內元素
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - 清除浮動
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 定位
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 位移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - z-index
- CSS - 底部
- CSS - 導航欄
- CSS - 覆蓋層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode 雙向演算法
- CSS - min-content
- CSS - all
- CSS - inset
- CSS - isolation
- CSS - overscroll
- CSS - justify-items
- CSS - justify-self
- CSS - tab-size
- CSS - pointer-events
- CSS - place-content
- CSS - place-items
- CSS - place-self
- CSS - max-block-size
- CSS - min-block-size
- CSS - mix-blend-mode
- CSS - max-inline-size
- CSS - min-inline-size
- CSS - offset
- CSS - accent-color
- CSS - user-select
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - !important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多重背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - box-decoration-break
- CSS - caret-color
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - box-sizing
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 圖片樣式
- CSS - 特效性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - 畫素到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - 文字裝飾
text-decoration 屬性用於向內聯內容新增“裝飾”,例如文字下劃線、上劃線、刪除線和中劃線。
它是一個簡寫屬性,對應以下屬性:
text-decoration-line:設定裝飾線的型別(下劃線、刪除線或上劃線)。
text-decoration-color:設定文字裝飾的顏色。
text-decoration-style:設定文字裝飾的樣式(點狀、虛線、實線、波浪線、雙線等)。
text-decoration-thickness:設定文字裝飾的粗細。
文字裝飾線
text-decoration-line 屬性用於向文字新增裝飾線,例如下劃線。
可能的值
none − 不應向內聯文字新增任何裝飾。
underline − 在內聯文字下方繪製下劃線。
overline − 在內聯文字上方繪製上劃線。
line-through − 應在內聯文字中間繪製一條線。
blink − 內聯文字應閃爍,類似於 Netscape 引入的 BLINK 元素。
應用於
所有 HTML 元素。
DOM 語法
object.style.textDecorationLine = "underline";
CSS text-decoration - 使用 text-decoration-line 屬性
<html>
<head>
</head>
<body>
<h2>Text Decoration Line</h2>
<p style="text-decoration-line: overline;">Overline text decoration.</p>
<p style="text-decoration-line: line-through;">Line-through text decoration.</p>
<p style="text-decoration-line: underline;">Underline text decoration.</p>
</body>
</html>
CSS text-decoration - 使用 text-decoration-color 屬性
text-decoration-color 屬性用於向文字裝飾線新增顏色。要使用此屬性,需要指定 text-decoration-line。
可能的值
關鍵字:作為關鍵字的顏色名稱。例如 = red。
十六進位制:十六進位制值。例如 = #00ffff。
rgb rgb 值。例如 = rgb(255,200,100)。
應用於
所有 HTML 元素。
DOM 語法
object.style.textDecorationColor = "#00ffff";
示例
讓我們來看一個例子
<html>
<head>
</head>
<body>
<h2>Text Decoration Color</h2>
<p style="text-decoration-line: overline; text-decoration-color: red">Overline text decoration.</p>
<p style="text-decoration-line: line-through; text-decoration-color: green">Line-through text decoration.</p>
<p style="text-decoration-line: underline; text-decoration-color: blue">Underline text decoration.</p>
</body>
</html>
CSS text-decoration - 使用 text-decoration-style 屬性
text-decoration-style 屬性用於向文字裝飾線新增樣式。要使用此屬性,需要指定 text-decoration-line。
可能的值
solid
dotted
dashed
double
ridge
inset
outset
應用於
所有 HTML 元素。
DOM 語法
object.style.textDecorationStyle = "dotted";
示例
讓我們來看一個例子
<html>
<head>
</head>
<body>
<h2>Text Decoration Style</h2>
<p style="text-decoration-line: overline; text-decoration-style: dashed">Overline text decoration.</p>
<p style="text-decoration-line: line-through; text-decoration-style: solid">Line-through text decoration.</p>
<p style="text-decoration-line: underline; text-decoration-style: dotted">Underline text decoration.</p>
</body>
</html>
CSS text-decoration - 使用 text-decoration-thickness 屬性
text-decoration-thickness 屬性用於向文字裝飾線新增粗細。要使用此屬性,需要指定 text-decoration-line。
可能的值
長度:任何長度值(以 px、pt、in、cm 等表示)。
auto:瀏覽器選擇合適的寬度。
百分比:將粗細指定為當前字型中 1em 的百分比。
應用於
所有 HTML 元素。
DOM 語法
object.style.textDecorationThickness = "5px";
示例
讓我們來看一個例子
<html>
<head>
</head>
<body>
<h2>Text Decoration Thickness</h2>
<p style="text-decoration-line: overline; text-decoration-thickness: 2px">Overline text decoration.</p>
<p style="text-decoration-line: line-through; text-decoration-thickness: 1pt">Line-through text decoration.</p>
<p style="text-decoration-line: underline; text-decoration-thickness: 0.25in">Underline text decoration.</p>
</body>
</html>
CSS text-decoration - 使用 text-decoration-offset 屬性
text-underline-offset 屬性用於設定文字裝飾線與其原始位置的偏移距離。
text-underline-offset 屬性不是簡寫 text-decoration 的一部分。此屬性僅影響下劃線,而不影響 text-decoration-line 的其他值,例如刪除線或上劃線。
可能的值
auto:瀏覽器選擇合適的偏移量。
長度:任何長度值(以 px、pt、in、cm 等表示)。
百分比:將偏移量指定為當前字型中 1em 的百分比。
應用於
所有 HTML 元素。
DOM 語法
object.style.textUnderlineOffset = "2pt";
示例
讓我們來看一個例子
<html>
<head>
<style>
p {
padding: 10px;
}
</style>
</head>
<body>
<h2>Text Underline Offset</h2>
<p style="text-decoration-line: underline; text-decoration-style: wavy; text-underline-offset: 1em;">Offset for underline.</p>
<p style="text-decoration-line: overline; text-decoration-style: dotted; text-underline-offset: 1in;">No offset for overline.</p>
</body>
</html>
CSS text-decoration - 使用 text-underline-position 屬性
text-underline-position 屬性用於設定文字裝飾線(僅限下劃線)與其原始位置的位置。
text-underline-offset 屬性不是簡寫 text-decoration 的一部分。此屬性僅影響下劃線,而不影響 text-decoration-line 的其他值,例如刪除線或上劃線。
可能的值
auto:瀏覽器選擇合適的位置,位於或低於文字基線。
under:將線條放在基線下方。
left:將線條放在左側(對於垂直書寫模式);以及下方(對於水平書寫模式)。
right:將線條放在右側(對於垂直書寫模式);以及下方(對於水平書寫模式)。
under left:將線條放在基線左側下方。
right under:將線條放在基線右側下方。
應用於
所有 HTML 元素。
DOM 語法
object.style.textUnderlinePosition = "under";
示例
讓我們來看一個例子
<html>
<head>
</head>
<body>
<h2>Text Underline Position</h2>
<p style="text-decoration-line: underline; text-underline-position: under;">Position of line under the baseline.</p>
</body>
</html>