HTML DOM 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>本教程(w3big.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>本教程(w3big.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>
嘗試一下»
Style對象