自强学堂
自强学堂:学习、分享、让你更强!
JavaScript 参考手册HTMLCSSJAVASCRIPTJQUERYSQLPHPBOOTSTRAPANGULARXML
 

HTML DOM Style textIndent 属性

Style 对象参考手册 Style 对象

定义和用法

textIndent 属性设置或返回文本第一行的缩进。

语法

设置 textIndent 属性:

Object.style.textIndent="length|%|inherit"

返回 textIndent 属性:

Object.style.textIndent

描述
length使用 px、cm 等单位定义缩进。默认值是 0。
%定义缩进为父元素宽度的百分比。
inherittextIndent 属性的值从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 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>

尝试一下 »


Style 对象参考手册 Style 对象