在 HTML 中使用 text-decoration 属性可为文本添加下划线:用 <span> 或 <div> 元素标识文本。添加 style 属性,设置 text-decoration 为 underline。

如何使用 HTML 设置下划线
在 HTML 中,可以使用 text-decoration 属性为文本添加下划线。
步骤:
- 使用
<span>或<div>元素标识要加下划线的文本。 - 在该元素中添加
style属性,设置text-decoration为underline。
语法:
立即学习“前端免费学习笔记(深入)”;
<code class="html"><element style="text-decoration: underline;">要加下划线的文本</element></code>
示例:
<code class="html"><p>这是带下划线的文本。</p> <div style="text-decoration: underline;"> 这是带下划线的文本,位于一个 <div> 元素中。 </div></code>
笔记:
-
text-decoration属性还可以设置其他类型的文本修饰,例如删除线和上划线。 - 也可以使用 CSS 类来设置下划线。例如,创建一个名为 "underline" 的 CSS 类:
<code class="css">.underline {
text-decoration: underline;
}</code>然后在 HTML 中使用该类:
<code class="html"><p class="underline">这是带下划线的文本。</p></code>











