大网数据广告活动
Web 标准与前端开发

text-decoration

· 52CE 我爱测

**`text-decoration`** CSS 简写属性设置文本上的装饰性线条的外观。它是 text-decoration-line、text-decoration-color、text-decoration-style 和较新的 text-decoration-thickness 属性的缩写。

text-decoration CSS 简写属性设置文本上的装饰性线条的外观。它是 text-decoration-line、text-decoration-color、text-decoration-style 和较新的 text-decoration-thickness 属性的缩写。

CSS Demo: text-decoration

text-decoration: underline;
text-decoration: underline dotted;
text-decoration: underline dotted red;
text-decoration: green wavy underline;
text-decoration: underline overline #ff3028;
<section id="default-example">
  <p>
    I'd far rather be
    <span class="transition-all" id="example-element">happy than right</span>
    any day.
  </p>
</section>
p {
  font: 1.5em sans-serif;
}

文本装饰会覆盖子文本元素。这意味着如果一个元素指定了文本装饰,那么子元素无法去除这个装饰。例如,在标记 <p>这段文字中有<em>一些强调词</em>。</p> 中,样式规则 p { text-decoration: underline; } 会导致整个段落包含下划线。样式规则 em { text-decoration: none; } 不会有任何变化;整个段落仍然会包含下划线。但是,规则 em { text-decoration: overline; } 会导致“一些强调词”上出现上划线。

属性构成

该属性是以下 CSS 属性的简写:

语法

text-decoration: underline;
text-decoration: overline red;
text-decoration: none;

/* 全局值 */
text-decoration: inherit;
text-decoration: initial;
text-decoration: revert;
text-decoration: revert-layer;
text-decoration: unset;

text-decoration 属性由一个或多个用空格分隔的值组成,表示各种普通文本装饰属性。

值

  • text-decoration-line
    • : 设置使用的装饰类型,例如 underline 或 line-through。
  • text-decoration-color
    • : 设置装饰的颜色。
  • text-decoration-style
    • : 设置装饰的线条的样式,例如 solid、wavy 或 dashed。
  • text-decoration-thickness
    • : 设置装饰的线条粗细。

形式定义

形式语法

示例

text-decoration 值的演示

.under {
  text-decoration: underline red;
}

.over {
  text-decoration: wavy overline lime;
}

.line {
  text-decoration: line-through;
}

.plain {
  text-decoration: none;
}

.underover {
  text-decoration: dashed underline overline;
}

.thick {
  text-decoration: solid underline purple 4px;
}

.blink {
  text-decoration: blink;
}
<p class="under">此文本下方有一行线。</p>
<p class="over">此文本上面有一行线。</p>
<p class="line">此文本有一条线穿过它。</p>
<p>
  此<a class="plain" href="#">链接不会具有下划线</a
  >,因为链接默认加下划线。移除锚点上的文本装饰时要小心,因为用户通常依赖下划线来表示超链接
</p>
<p class="underover">此文本在其上方<em>和</em>下方都有线条。</p>
<p class="thick">在浏览器支持的情况下,此文本具有非常粗的紫色下划线。</p>
<p class="blink">此文本可能会为你闪烁,具体取决于你使用的浏览器。</p>

text-decoration 值的演示

规范

浏览器兼容性

参见

  • 包括的文本装饰属性分别是 text-decoration-line、text-decoration-color、text-decoration-style 和 text-decoration-thickness。
  • text-decoration-skip-ink、text-underline-offset 和 text-underline-position 属性也会影响文本装饰,但不包括在该简写属性中。
  • list-style 属性控制 ol 和 ul 列表的每一项的外观。

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。