`text-decoration: underline` 只能畫實線,且位置固定。若需虛線、控制間距、顏色獨立,請用 border-bottom 方案。
a {
color: #3399FF;
font-weight: normal;
text-decoration: none; /* 關鍵:移除原生下劃線 */
border-bottom: 1px dotted #0099CC; /* 虛線下邊框 */
}
a:hover {
color: #4499EE;
border-bottom: 1px solid #0099CC; /* 懸停變實線增強反饋 */
}
border-bottom: 2px dashed #ccc(dashed 間距較大)border-bottom: 3px double #999a { transition: border-color .2s, color .2s; }| 特性 | text-decoration | border-bottom |
|---|---|---|
| 線型 | 僅實線 | solid/dashed/dotted/double/groove/ridge |
| 顏色獨立 | 跟隨字體色 | 可獨立設定 |
| 距離文字 | 固定 | 可用 padding-bottom 調整 |
| 動畫 | 不可動畫 | 可 transition |