在 CSS 中,通过 text-decoration: underline; 为文本添加下划线。此外,还可以定制下划线,包括偏移量、颜色和样式。要移除下划线,请使用 text-decoration: none;。

如何在 CSS 中设置下划线
在 CSS 中,可以使用 text-decoration 属性为文本添加下划线。
语法:
<code>text-decoration: underline;</code>
示例:
立即学习“前端免费学习笔记(深入)”;
<code class="css">p {
text-decoration: underline;
}</code>这样就会为段落中的所有文本添加下划线。
定制下划线:
- underline-offset: 偏移下划线相对于文本基线的垂直位置。
- underline-color: 设置下划线颜色。
- underline-style: 设置下划线样式,例如实线、波浪线或虚线。
示例:
立即学习“前端免费学习笔记(深入)”;
<code class="css">p {
text-decoration: underline 2px solid red;
}</code>这会在段落文本下添加一条 2 像素粗的红色实线下划线。
移除下划线:
要移除下划线,请使用 none 值:
<code class="css">p {
text-decoration: none;
}</code>










