lineheight
Style lineHeight 属性
定义和用法
lineHeight 属性设置或返回在文本中行之间的距离。
语法
设置 lineHeight 属性:
Object.style.lineHeight="normal|number|length|%|inherit"
返回 lineHeight 属性:
Object.style.lineHeight
值 | 描述 |
---|---|
normal | 默认。设置合理的行间距。 |
number | 设置数字,此数字会与当前的字体尺寸相乘来设置行间距。 |
length | 使用 px、cm 等单位定义行间距。 |
% | 定义行间距为当前字体尺寸的百分比。 |
inherit | lineHeight 属性的值从父元素继承。 |
浏览器支持
所有主要浏览器都支持 lineHeight 属性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !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>