--- title: text-decoration slug: Web/CSS/text-decoration tags: - 文本修饰 translation_of: Web/CSS/text-decoration ---
{{EmbedInteractiveExample("pages/css/text-decoration.html")}}
text-decoration
这个 CSS 属性是用于设置文本的修饰线外观的(下划线、上划线、贯穿线/删除线 或 闪烁)它是 {{cssxref("text-decoration-line")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-decoration-style")}}, 和新出现的 {{cssxref("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 }
则会在<em>标记的文字上再添加上这种overline样式。
text-decoration属性是一种简写属性,并且可以使用普通属性三个值中的任何一个。普通属性如下:{{cssxref("text-decoration-line")}},{{cssxref("text-decoration-color")}}和{{cssxref("text-decoration-style")}}
underline
,删除线line-through
wavy
实线solid
虚线dashed
<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="blink">This text might blink for you,
depending on the browser you use.</p>
.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;
}
.blink {
text-decoration: blink;
}
{{EmbedLiveSample('示例','auto','280')}}
规范 | 状态值 | 注解 |
---|---|---|
{{SpecName('CSS4 Text Decoration')}} | {{Spec2('CSS4 Text Decoration')}} | 增加了 {{cssxref("text-decoration-thickness")}}; 注意这个属性还不是正式的,还没有明确。 |
{{ SpecName('CSS3 Text Decoration', '#text-decoration-property', 'text-decoration') }} | {{ Spec2('CSS3 Text Decoration') }} | 转换为简写属性。支持{{ cssxref('text-decoration-style') }}值 |
{{ SpecName('CSS2.1', 'text.html#lining-striking-props', 'text-decoration') }} | {{ Spec2('CSS2.1') }} | 没有显著变化 |
{{ SpecName('CSS1', '#text-decoration', 'text-decoration') }} | {{ Spec2('CSS1') }} |
最初的规范 |
{{cssinfo}}
{{Compat("css.properties.text-decoration")}}