CSS text-decoration 属性
示例
为 <h1>、<h2> 和 <h3> 元素设置不同的文本装饰
h1 {
text-decoration: overline;
}
h2 {
text-decoration: line-through;
}
h3 {
text-decoration: underline;
}
h4 {
text-decoration: underline overline;
}
自己动手试一试 »
更多“自己尝试”的例子见下文。
定义和用法
text-decoration
属性指定添加到文本的装饰,它是以下属性的简写属性:
- text-decoration-line (必需)
- text-decoration-color
- text-decoration-style
- text-decoration-thickness
默认值 | none currentColor solid auto |
---|---|
继承 | no |
可动画 | 否,请参阅单个属性。 了解 animatable |
版本 | CSS1,在 CSS3 中更新 |
JavaScript 语法 | object.style.textDecoration="underline" 尝试一下 |
浏览器支持
表中的数字指定了完全支持该属性的第一个浏览器版本。
属性 | |||||
---|---|---|---|---|---|
text-decoration | 1.0 | 3.0 | 1.0 | 1.0 | 3.5 |
CSS 语法
text-decoration: text-decoration-line text-decoration-color text-decoration-style text-decoration-thickness|initial|inherit;
属性值
值 | 描述 | 演示 |
---|---|---|
text-decoration-line | 设置使用的文本装饰类型(例如下划线、上划线、删除线) | 演示 ❯ |
text-decoration-color | 设置文本装饰的颜色 | 演示 ❯ |
text-decoration-style | 设置文本装饰的样式(例如实线、波浪线、点状、虚线、双线) | 演示 ❯ |
text-decoration-thickness | 设置装饰线的粗细 | |
initial | 将此属性设置为其默认值。阅读关于initial | |
inherit | 从其父元素继承此属性。阅读关于inherit |
更多示例
示例
添加更多文本装饰
h1 {
text-decoration: underline overline dotted red;
}
h2 {
text-decoration: underline wavy blue 5px;
}
自己动手试一试 »
相关页面
CSS 教程:CSS 文本装饰
HTML DOM 参考:textDecoration 属性