Latest web development tutorials

HTML DOM Style wordSpacing 屬性

Style 對象參考手冊 Style對象

定義和用法

wordSpacing 屬性設置或返回文本中單詞之間的空間。

語法

設置wordSpacing 屬性:

Object.style.wordSpacing="normal|length|inherit"

返回wordSpacing 屬性:

Object.style.wordSpacing

描述
normal 默认。定义单词间的标准空间。
length 使用 px、cm 等单位定义单词间的空间。可使用负值。
inherit wordSpacing 属性的值从父元素继承。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持wordSpacing 屬性。

注意: IE7及更早的版本不支持"inherit"值。IE8 只有規定了!DOCTYPE 才支持"inherit"。 IE9 支持"inherit"。


實例

實例

更改單詞間的空間:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
    document.getElementById("p1").style.wordSpacing="50px";
}
</script>
</head>
<body>

<p id="p1">这 是 一 些 文 本。</p>
<br>
<button type="button" onclick="displayResult()">修改空间</button>

</body>
</html>

嘗試一下»


Style 對象參考手冊 Style對象