Style textIndent 屬性
Style 對象定義和用法
textIndent 屬性設置或返回文本第一行的縮進。
語法
設置 textIndent 屬性:
Object.style.textIndent="length|%|inherit"
返回 textIndent 屬性:
Object.style.textIndent
值 | 描述 |
---|---|
length | 使用 px、cm 等單位定義縮進。默認值是 0。 |
% | 定義縮進為父元素寬度的百分比。 |
inherit | textIndent 屬性的值從父元素繼承。 |
瀏覽器支持
所有主要瀏覽器都支持 textIndent 屬性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規(guī)定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。
實例
實例
縮進文本:
<html>
<head>
<script>
function displayResult()
{
document.getElementById("div1").style.textIndent="50px";
}
</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()">Indent text</button>
</body>
</html>
<head>
<script>
function displayResult()
{
document.getElementById("div1").style.textIndent="50px";
}
</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()">Indent text</button>
</body>
</html>
嘗試一下 ?
Style 對象
更多建議: