Style textIndent 属性
Style 对象定义和用法
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"。
实例
实例
缩进文本:
<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 对象
更多建议: