HTML DOM Style tabSize 属性
htmldomweb developmentfront end technology更新于 2025/11/29 22:36:17
HTML DOM Style tabSize 属性返回并修改 HTML 文档中制表符所用空格的长度。
语法
以下是语法 −
1. 返回 tabSize
object.tabSize
2. 修改 tabSize
object.tabSize = “value”
此处值可以为 -
| 值 | 说明 |
|---|---|
| initial | 将此属性值设置为默认值。 |
| inherit | 从其父元素继承此属性值。 |
| length | 指定制表符的长度。 |
| number | 指定 HTML 文档中每个制表符应显示的空格字符数。 |
让我们看一个 HTML DOM Style tabSize 属性的示例 −
示例
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem 0;
}
.square {
width: 100px;
height: 100px;
background: #db133a6b;
position: relative;
}
.show {
font-size: 1.2rem;
margin: 1rem 0;
}
</style>
<body>
<h1>DOM Style tabSize Property Demo</h1>
<pre>I'mpreelement.</pre>
<button onclick="set()" class="btn">Change tabSize</button>
<script>
function set() {
document.querySelector('pre').style.tabSize = "20";
}
</script>
</body>
</html>
输出

点击"更改标签大小"按钮来更改预元素的标签大小。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

