小码哥的IT人生

HTML DOM textIndent 属性

JavaScript基础 2022-06-08 14:52:09小码哥的IT人生shichen

HTML DOM textIndent 属性

定义和用法

textIndent 属性缩进元素中的首行文本。

语法:

Object.style.textIndent=length|%

可能的值

描述
length 定义固定的缩进。默认值:0。
% 定义基于父元素宽度的百分比的缩进。

实例

本例缩进文本:

<html>
<head>
<script type="text/javascript">
function setTextIndent()
{
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 />
<input type="button" onclick="setTextIndent()"
value="Indent first line of text" />
</body>
</html>

TIY

完整实例【textIndent - 缩进文本】:

<html>
<head>
<script type="text/javascript">
function setTextIndent()
{
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 />
<input type="button" onclick="setTextIndent()" value="Indent first line of text" />
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024