Style lineHeight 屬性
Style 對象定義和用法
lineHeight 屬性設(shè)置或返回在文本中行之間的距離。
語法
設(shè)置 lineHeight 屬性:
Object.style.lineHeight="normal|number|length|%|inherit"
返回 lineHeight 屬性:
Object.style.lineHeight
值 | 描述 |
---|---|
normal | 默認(rèn)。設(shè)置合理的行間距。 |
number | 設(shè)置數(shù)字,此數(shù)字會與當(dāng)前的字體尺寸相乘來設(shè)置行間距。 |
length | 使用 px、cm 等單位定義行間距。 |
% | 定義行間距為當(dāng)前字體尺寸的百分比。 |
inherit | lineHeight 屬性的值從父元素繼承。 |
瀏覽器支持
所有主要瀏覽器都支持 lineHeight 屬性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規(guī)定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。
實例
實例
更改行的高度:
<html>
<head>
<script>
function displayResult()
{
document.getElementById("div1").style.lineHeight="2";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
<br>
<button type="button" onclick="displayResult()">Change line height</button>
</body>
</html>
<head>
<script>
function displayResult()
{
document.getElementById("div1").style.lineHeight="2";
}
</script>
</head>
<body>
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
<br>
<button type="button" onclick="displayResult()">Change line height</button>
</body>
</html>
嘗試一下 ?
Style 對象
更多建議: