Style textDecorationLine 属性 详解
css3基础 2023-07-30 03:14:22小码哥的IT人生shichen
Style textDecorationLine 属性
定义和用法
textDecorationLine 属性设置或返回装饰将获得的线条类型(如果有)。
注释:您还可以使用 textDecoration 属性设置 textDecorationLine,该属性是以下属性的简写属性:
注释:您还可以组合多个值,比如 underline 和 overline,以在文本下方和上方同时显示线条。
另请参阅:
CSS 参考手册:text-decoration-line 属性
实例
显示顶部有一条线的段落:
document.getElementById("myP").style.textDecorationLine = "overline";
完整实例【亲自试一试】:
<!DOCTYPE html>
<html>
<head>
<style>
p#demo {
text-decoration: underline;
}
</style>
</head>
<body>
<p id="demo">
Hello world!
</p>
<p>点击“试一试”按钮可更改段落的 text-decoration-line。</p>
<button onclick="myFunction()">试一试</button>
<script>
function myFunction() {
document.getElementById("demo").style.textDecorationLine = "line-through";
}
</script>
</body>
</html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html
语法
返回 textDecorationLine 属性:
object.style.textDecorationLine
设置 textDecorationLine 属性:
object.style.textDecorationLine = "none|underline|overline|line-through|initial|inherit"
属性值
| 值 | 描述 |
|---|---|
| none | 默认值。规定文本装饰没有线。 |
| underline | 规定将在文本下方显示一条线。 |
| overline | 规定将在文本上显示一条线。 |
| line-through | 规定将穿过文本显示一条线。 |
| initial | 将此属性设置为其默认值。请参阅 initial。 |
| inherit | 从其父元素继承此属性。请参阅 inherit。 |
技术细节
| 默认值: | 无 |
|---|---|
| 返回值: | 字符串,表示元素的 text-decoration-line 属性。 |
| CSS 版本: | CSS3 |
浏览器支持
表中的数字注明了首个完全支持该属性的浏览器版本。
| Chrome | Edge | Firefox | Safari | Opera |
|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Opera |
| 57.0 | 79.0 | 36.0 | 7.0 Webkit | 44.0 |

