天天看點

Style direction 屬性

Style 對象

定義和用法

direction 屬性設定或傳回元素的文本方向。

文法

設定 direction 屬性:

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

傳回 direction 屬性:

Object.style.direction

描述
ltr 預設。文本流從左到右。
rtl 文本流從右到左。
inherit 文本方向從父元素繼承。

浏覽器支援

Style direction 屬性
Style direction 屬性
Style direction 屬性
Style direction 屬性
Style direction 屬性

所有主要浏覽器都支援 direction 屬性。

注意:

IE7 及更早的版本不支援 "inherit" 值。IE8 隻有規定了 !DOCTYPE 才支援 "inherit"。IE9 支援 "inherit"。

執行個體

把文本流設定為從右到左:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>菜鳥教程(runoob.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>

Style 對象