Latest web development tutorials

HTML DOM Style textAlign property

Style Object Reference Style Objects

Definition and Usage

textAlign property sets or returns to block-level elements of the Chinese horizontal alignment.

grammar

Setting textAlign properties:

Object.style.textAlign="left|right|center|justify|inherit"

Back textAlign properties:

Object.style.textAlign

描述
left 默认。把文本排列到左边。
right 把文本排列到右边。
center 把文本排列到中间。
justify 根据 textJustify 属性对齐文本。
inherit textAlign 属性的值从父元素继承。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support textAlign property.

Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".


Examples

Examples

Align p elements of text:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
    document.getElementById("p1").style.textAlign="center";
}
</script>
</head>
<body>

<p id="p1">这是一些文本。</p>
<br>
<button type="button" onclick="displayResult()">对齐文本</button>

</body>
</html>

try it"


Style Object Reference Style Objects