writing-mode
CSS
property sets whether lines of text are laid out horizontally or vertically, as well as the direction in which blocks progress. When set for an entire document, it should be set on the root element (
html
element for HTML documents).
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
This property specifies the block flow direction , which is the direction in which block-level containers are stacked, and the direction in which inline-level content flows within a block container. Thus, it also determines the ordering of block-level content.
/* Keyword values */ writing-mode: horizontal-tb; writing-mode: vertical-rl; writing-mode: vertical-lr; /* Global values */ writing-mode: inherit; writing-mode: initial; writing-mode: unset;
writing-mode
property is specified as one of the values listed below. The flow direction in horizontal scripts is also affected by the
directionality of that script
, either left-to-right (
ltr
, like English and most other languages) or right-to-left (
rtl
, like Hebrew or Arabic).
horizontal-tb
ltr
scripts, content flows horizontally from left to right. For
rtl
scripts, content flows horizontally from right to left. The next horizontal line is positioned below the previous line.
vertical-rl
ltr
scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the left of the previous line. For
rtl
scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the right of the previous line.
vertical-lr
ltr
scripts, content flows vertically from top to bottom, and the next vertical line is positioned to the right of the previous line. For
rtl
scripts, content flows vertically from bottom to top, and the next vertical line is positioned to the left of the previous line.
sideways-rl
ltr
scripts, content flows vertically from bottom to top. For
rtl
scripts, content flows vertically from top to bottom. All the glyphs, even those in vertical scripts, are set sideways toward the right.
sideways-lr
ltr
scripts, content flows vertically from top to bottom. For
rtl
scripts, content flows vertically from bottom to top. All the glyphs, even those in vertical scripts, are set sideways toward the left.
lr
horizontal-tb
代替。
lr-tb
horizontal-tb
代替。
rl
horizontal-tb
代替。
tb
vertical-lr
代替。
tb-lr
vertical-lr
代替。
tb-rl
vertical-rl
代替。
| 初始值 |
horizontal-tb
|
|---|---|
| 适用于 | all elements except table row groups, table column groups, table rows, and table columns |
| 继承 | yes |
| 计算值 | 如指定 |
| 动画类型 | discrete |
horizontal-tb | vertical-rl | vertical-lr | sideways-rl | sideways-lr
This example demonstrates all of the writing modes, showing each with text in various languages.
The HTML is a
<table>
with each writing mode in a row with a column showing text in various scripts using that writing mode.
<table>
<tr>
<th>Value</th>
<th>Vertical script</th>
<th>Horizontal (LTR) script</th>
<th>Horizontal (RTL) script</th>
<th>Mixed script</th>
</tr>
<tr>
<td>horizontal-tb</td>
<td class="example Text1"><span>我家没有电脑。</span></td>
<td class="example Text1"><span>Example text</span></td>
<td class="example Text1"><span>מלל ארוך לדוגמא</span></td>
<td class="example Text1"><span>1994年に至っては</span></td>
</tr>
<tr>
<td>vertical-lr</td>
<td class="example Text2"><span>我家没有电脑。</span></td>
<td class="example Text2"><span>Example text</span></td>
<td class="example Text2"><span>מלל ארוך לדוגמא</span></td>
<td class="example Text2"><span>1994年に至っては</span></td>
</tr>
<tr>
<td>vertical-rl</td>
<td class="example Text3"><span>我家没有电脑。</span></td>
<td class="example Text3"><span>Example text</span></td>
<td class="example Text3"><span>מלל ארוך לדוגמא</span></td>
<td class="example Text3"><span>1994年に至っては</span></td>
</tr>
<tr>
<td>sideways-lr</td>
<td class="example Text4"><span>我家没有电脑。</span></td>
<td class="example Text4"><span>Example text</span></td>
<td class="example Text4"><span>מלל ארוך לדוגמא</span></td>
<td class="example Text4"><span>1994年に至っては</span></td>
</tr>
<tr>
<td>sideways-rl</td>
<td class="example Text5"><span>我家没有电脑。</span></td>
<td class="example Text5"><span>Example text</span></td>
<td class="example Text5"><span>מלל ארוך לדוגמא</span></td>
<td class="example Text5"><span>1994年に至っては</span></td>
</tr>
</table>
Some preparatory CSS just to make things look a little better:
table {
border-collapse:collapse;
}
td, th {
border: 1px black solid; padding: 3px;
}
th {
background-color: lightgray;
}
.example {
height:75px;
width:75px;
}
The CSS that adjusts the directionality of the content looks like this:
.example.Text1 span, .example.Text1 {
writing-mode: horizontal-tb;
-webkit-writing-mode: horizontal-tb;
-ms-writing-mode: horizontal-tb;
}
.example.Text2 span, .example.Text2 {
writing-mode: vertical-lr;
-webkit-writing-mode: vertical-lr;
-ms-writing-mode: vertical-lr;
}
.example.Text3 span, .example.Text3 {
writing-mode: vertical-rl;
-webkit-writing-mode: vertical-rl;
-ms-writing-mode: vertical-rl;
}
.example.Text4 span, .example.Text4 {
writing-mode: sideways-lr;
-webkit-writing-mode: sideways-lr;
-ms-writing-mode: sideways-lr;
}
.example.Text5 span, .example.Text5 {
writing-mode: sideways-rl;
-webkit-writing-mode: sideways-rl;
-ms-writing-mode: sideways-rl;
}
This image shows what the output should look like, in case your browser's support for
writing-mode
is incomplete:
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Writing Modes Level 4
The definition of 'writing-mode' in that specification. |
候选推荐 |
Add
sideways-lr
and
sideways-rl
|
|
CSS Writing Modes Module Level 3
The definition of 'writing-mode' in that specification. |
Proposed Recommendation | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
writing-mode
|
Chrome 完整支持 48 | Edge 完整支持 12 |
Firefox
完整支持
41
注意事项
|
IE
完整支持
9
注意事项
|
Opera 完整支持 35 | Safari 完整支持 10.1 | WebView Android 完整支持 48 | Chrome Android 完整支持 48 |
Firefox Android
完整支持
41
注意事项
|
Opera Android 完整支持 35 | Safari iOS 完整支持 10.3 | Samsung Internet Android 完整支持 5.0 |
horizontal-tb
,
vertical-lr
,和
vertical-rl
|
Chrome 完整支持 48 | Edge 完整支持 79 | Firefox 完整支持 43 | IE 不支持 No | Opera 完整支持 35 | Safari 完整支持 9 | WebView Android 完整支持 48 | Chrome Android 完整支持 48 | Firefox Android 完整支持 43 | Opera Android 完整支持 35 | Safari iOS 完整支持 9 | Samsung Internet Android 完整支持 5.0 |
sideways-lr
and
sideways-rl
|
Chrome 不支持 No | Edge 不支持 No | Firefox 完整支持 43 | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 完整支持 43 | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
lr
,
lr-tb
,
rl
,
rl-tb
,
tb
,和
tb-rl
弃用
|
Chrome 完整支持 48 | Edge 完整支持 12 | Firefox 完整支持 43 | IE 完整支持 9 | Opera 完整支持 35 | Safari 完整支持 10.1 | WebView Android 完整支持 48 | Chrome Android 完整支持 48 | Firefox Android 完整支持 43 | Opera Android 完整支持 35 | Safari iOS 完整支持 10.3 | Samsung Internet Android 完整支持 5.0 |
完整支持
不支持
弃用。不要用于新网站。
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
writing-mode
attribute
direction
unicode-bidi
text-orientation
text-combine-upright
direction
text-combine-upright
text-orientation
unicode-bidi
writing-mode