Latest web development tutorials

HTML DOM Style direction property

Style Object Reference Style Objects

Definition and Usage

direction property sets or returns the text direction of the element.

grammar

Setting direction properties:

Object.style.direction="ltr|rtl|inherit"

Returns direction attributes:

Object.style.direction

描述
ltr 默认。文本流从左到右。
rtl 文本流从右到左。
inherit 文本方向从父元素继承。

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the direction property.

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


Examples

Examples

The text flows from right to left is set to:

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

<p id="p1">这是一些文本。</p>
<br>
<button type="button" onclick="displayResult()">设置文本方向从左到右</button>

</body>
</html>

try it"


Style Object Reference Style Objects