HTML DOM 样式 wordSpacing 属性
htmlweb developmentfront end technology更新于 2025/6/11 6:36:17
HTML DOM 样式 wordSpacing 属性返回并修改 HTML 文档中文本单词之间的间距。
语法
以下是语法 −
返回 wordSpacing
object.style.wordSpacing
修改 wordSpacing
object.style.wordSpacing = “value”
值
此处,值可以是 -
| 值 | 说明 |
|---|---|
| initial | 将此属性值设置为其默认值。 |
| inherit | 从其父元素继承此属性值。 |
| normal | 设置单词之间的正常间距。 |
| length | 以长度单位定义单词之间的间距。 |
示例
让我们看一个 HTML DOM 样式 wordSpacing 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background: lightblue;
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;
}
</style>
</head>
<body>
<h1>DOM Style wordSpacing Property Example</h1>
<p>This is a paragraph element.</p>
<button onclick="add()" class="btn">Change wordSpacing</button>
<script>
function add() {
document.querySelector('p').style.wordSpacing = "30px"
}
</script>
</body>
</html>
输出
这将产生以下输出 −

点击“更改单词间距”按钮来更改单词间距 −

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

