萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Div CSS 教學

CSS text-decoration 進階:多重裝飾、顏色樣式控制與 skip 特性

基礎屬性回顧

text-decoration: none | underline | overline | line-through | blink | inherit
/* 顏色由 color 屬性決定 */

現代 CSS3 擴展屬性 (組合用法)

text-decoration-line: underline overline;      /* 多重線條 */
text-decoration-color: #f06d06;                /* 線條顏色獨立於文字色 */
text-decoration-style: solid | double | dotted | dashed | wavy; /* 線條樣式 */
text-decoration-skip: ink | spaces | edges | objects; /* 避開下沉字形、空格、邊緣、行內元素 */

視覺效果示例

多重裝飾線

a { text-decoration: underline overline; }
上下雙線效果

自定義線條顏色

a { text-decoration-color: #f06d06; }
彩色下劃線

瀏覽器渲染差異:Gecko (Firefox) 下劃線在字形下方;WebKit/Blink (Chrome/Safari) 在字形上方。

瀏覽器下劃線位置差異

波浪線等樣式

a { text-decoration-style: wavy; }
波浪線效果

border-bottom 無法實現波浪/虛線等豐富樣式。

text-decoration-skip 增強可讀性

避開下沉字形 (g, y, p 等) 的下劃線:

a { text-decoration-skip: ink; }
skip ink 效果

配合半透明色降低對比度:

a { 
  text-decoration-color: rgba(0,0,0,.4);
  text-decoration-skip: ink;
}
半透明下劃線

skip 更多值

  • spaces:跳過空白字符
  • edges:首尾留白
  • objects:跳過行內替換元素 (img, input 等)
skip 多值效果

Safari/iOS 似乎默認啟用部分 skip 行為。

兼容性與降級策略

  • 新屬性 (text-decoration-color/style/skip) 僅現代瀏覽器支援
  • 生產環境常用 border-bottom + padding-bottom 模擬下劃線,控制力更強
  • @supports 查詢增強:
@supports (text-decoration-style: wavy) {
  a { text-decoration: underline; text-decoration-style: wavy; }
}
copyright © 萬盛學電腦網 all rights reserved