在 html 中使用 text-decoration 属性可为文本添加下划线:用 或 元素标识文本。添加 style 属性,设置 text-decoration 为 underline。
如何使用 HTML 设置下划线
在 HTML 中,可以使用 text-decoration 属性为文本添加下划线。
步骤:
- 使用
<span></span> 或 <div> 元素标识要加下划线的文本。<li><strong>在该元素中添加 <code>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>
<p><strong>笔记:</strong></p>
<ul>
<li>
<code>text-decoration</code> 属性还可以设置其他类型的文本修饰,例如删除线和上划线。</li>
<li>也可以使用 CSS 类来设置下划线。例如,创建一个名为 "underline" 的 CSS 类:</li>
</ul>
<pre class="brush:php;toolbar:false"><code class="<a style='color:#f60; text-decoration:underline;' href=" https: target="_blank">css">.underline {
text-decoration: underline;
}</code>
登录后复制
然后在 HTML 中使用该类:
<code class="html"><p class="underline">这是带下划线的文本。</p></code>
登录后复制






