DIV CSS 佈局教程網

CSS text-decoration:underline 為文字加上底線
編輯:布局基本知識     

text-decoration:underline 是用 CSS 為文字加上底線的標準寫法。兩個名詞拆开看就很清楚:text-decoration 是「文字裝飾」,underline 是「底線」。

一、語法

text-decoration: underline;

二、實作範例

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>text-decoration underline 範例</title>
<style>
.ab { text-decoration: underline; }
</style>
</head>
<body>
測試文字,範例內容 <span class="ab">這段有底線</span>!
</body>
</html>

只有 span 包住的片段帶底線,其餘維持原樣。

三、text-decoration 的其他值

overline:上標線。
line-through:刪除線(即橫線劃過文字中央)。
none:移除所有裝飾線,常用來拿掉超連結的預設底線。

它可以複寫多個值,以空格分隔:text-decoration: underline overline;

四、底線的進階控制

CSS 也提供了更細緻的底線樣式屬性,可獨立調整線條外觀:

.link {
text-decoration-line: underline;
text-decoration-style: wavy;
text-decoration-color: #F00;
text-decoration-thickness: 2px;
text-underline-offset: 4px; /* 底線與文字的距離 */
}

其中 text-underline-offset 特別有用——它能拉開底線與文字之間的距離,避免底線壓到 p、g、y 這類有下伸筆畫的字母。

五、底線顏色與文字顏色分離

若想要「文字黑色、底線紅色」的效果,用上述的 text-decoration-color 即可,不必再繞路用 border-bottom。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved