Style textIndent 屬性

定義和用法
textIndent 屬性設置或返回文本第一行的縮進。
語法
設置 textIndent 屬性:
Object.style.textIndent="length|%|inherit"
返回 textIndent 屬性:
Object.style.textIndent
值 | 描述 |
---|---|
length | 使用 px、cm 等單位定義縮進。默認值是 0。 |
% | 定義縮進為父元素寬度的百分比。 |
inherit | textIndent 屬性的值從父元素繼承。 |
流覽器支持
所有主要流覽器都支持 textIndent 屬性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。
實例
實例
縮進文本:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
document.getElementById("div1").style.textIndent="50px";
}
</script>
</head>
<body>
<div id="div1">
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
</div>
<br>
<button type="button" onclick="displayResult()">縮進文本</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
document.getElementById("div1").style.textIndent="50px";
}
</script>
</head>
<body>
<div id="div1">
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
這是一些文本。這是一些文本。
</div>
<br>
<button type="button" onclick="displayResult()">縮進文本</button>
</body>
</html>
