CSS

方向 | direction

direction

directionCSS属性设置文本,表格列和水平溢出的方向。使用rtl表示从右到左(如希伯来语或阿拉伯语)写的语言,以及ltr表示从左到右写的语言(如英语和大多数其他语言)。请注意,文本方向通常在文档中定义(例如,使用HTML的dir属性),而不是直接使用direction属性。

/* Keyword values */ direction: ltr; direction: rtl; /* Global values */ direction: inherit; direction: initial; direction: unset;

该属性设置块级元素的基本文本方向和unicode-bidi属性创建的嵌入方向。它还设置文本的默认对齐方式,块级元素以及单元格在表格行中的流向。

与HTML中的属性dir不同,属性direction不会从表格列继承到表格单元格,因为CSS继承遵循文档树结构,而表格单元格在行内而不在列内。

directionunicode-bidi属性是两个唯一不受简写属性all影响的属性。

Initial valueltr
Applies toall elements
Inheritedyes
Mediavisual
Computed valueas specified
Animation typediscrete
Canonical orderthe unique non-ambiguous order defined by the formal grammar

语法

可能值

ltr——文本和其他元素从左到右排列。这是默认值。

要想该direction属性对内联级元素产生任何影响,该unicode-bidi属性的值必须是embedoverride

形式语法

ltr | rtl

实例

blockquote { direction: rtl; }

规范

SpecificationStatusComment
CSS Writing Modes Module Level 3The definition of 'direction' in that specification.Candidate RecommendationNo change.
CSS Level 2 (Revision 1)The definition of 'direction' in that specification.RecommendationInitial definition.

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support2.0(Yes)1.0 (1.7 or earlier)5.59.21.3

FeatureAndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support1.0(Yes)1.0 (1.0)683.1