text-decoration: underline 的顏色**永遠跟隨文字顏色**(color),無法單獨設定。
.underline-red {
border-bottom: 1px solid #f00; /* 紅色實線 */
color: #000; /* 文字黑色 */
text-decoration: none; /* 關閉原生底線 */
}
.underline-blue-dashed {
border-bottom: 2px dashed #00f; /* 藍色虛線 */
color: #090; /* 文字綠色 */
}
padding-bottom: 2px; 控制底線與文字距離。display: inline-block; width: 100px; 限制底線長度。transition: border-bottom-color .3s; 滑鼠懸停變色。<style>
.divcss-aa { border-bottom: 1px dashed #f00; color: #0ff; }
.divcss-bb { border-bottom: 1px solid #00f; color: #090; }
</style>
<p class="divcss-aa">紅色虛線底線,天藍文字</p>
<p class="divcss-bb">藍色實線底線,綠色文字</p>
text-decoration: underline 2px solid #f00; /* CSS Text Decoration Level 3 */
text-decoration-color: #f00;
text-decoration-style: wavy;
text-decoration-thickness: 2px;
支援度:Firefox 36+、Chrome 57+、Safari 12.1+、Edge 79+。IE 不支援,仍需 border-bottom 方案。