text-decoration

**text-decoration** 简写 CSS 属性设置文本装饰线的显示方式。它是 text-decoration-linetext-decoration-colortext-decoration-style 和较新的 text-decoration-thickness 属性的简写。

试试看

文本装饰绘制在后代文本元素上。这意味着,如果元素指定了文本装饰,那么子元素就不能删除该装饰。例如,在标记 <p>This text has <em>some emphasized words</em> in it.</p> 中,样式规则 p { text-decoration: underline; } 将导致整个段落被下划线。样式规则 em { text-decoration: none; } 不会导致任何变化;整个段落仍将被下划线。但是,规则 em { text-decoration: overline; } 将导致在 “some emphasized words” 上出现第二个装饰。

组成属性

语法

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

/* Global values */
text-decoration: inherit;
text-decoration: initial;
text-decoration: revert;
text-decoration: revert-layer;
text-decoration: unset;

text-decoration 属性被指定为一个或多个用空格分隔的值,表示各种长文本装饰属性。

text-decoration-line

设置所使用的装饰类型,例如 underlineline-through

text-decoration-color

设置装饰的颜色。

text-decoration-style

设置用于装饰的线的样式,例如 solidwavydashed

text-decoration-thickness

设置用于装饰的线的粗细。

正式定义

初始值与简写中每个属性的初始值相同
应用于所有元素。它也应用于 ::first-letter::first-line.
继承
计算值与简写中每个属性的初始值相同
动画类型与简写中每个属性的初始值相同

正式语法

text-decoration = 
<'text-decoration-line'> ||
<'text-decoration-style'> ||
<'text-decoration-color'>

<text-decoration-line> =
none |
[ underline || overline || line-through || blink ]

<text-decoration-style> =
solid |
double |
dotted |
dashed |
wavy

<text-decoration-color> =
<color>

示例

文本装饰值的演示

css
.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;
}
html
<p class="under">This text has a line underneath it.</p>
<p class="over">This text has a line over it.</p>
<p class="line">This text has a line going through it.</p>
<p>
  This <a class="plain" href="#">link will not be underlined</a>, as links
  generally are by default. Be careful when removing the text decoration on
  anchors since users often depend on the underline to denote hyperlinks.
</p>
<p class="underover">This text has lines above <em>and</em> below it.</p>
<p class="thick">
  This text has a really thick purple underline in supporting browsers.
</p>
<p class="blink">
  This text might blink for you, depending on the browser you use.
</p>

结果

规范

规范
CSS 文本装饰模块级别 3
# text-decoration 属性

浏览器兼容性

BCD 表仅在浏览器中加载

另请参阅