核心屬性
| 屬性 | 值 | 說明 |
writing-mode | vertical-rl / vertical-lr / horizontal-tb | 標準屬性:垂直右→左 / 垂直左→右 / 水平上→下 |
text-orientation | mixed / upright / sideways | 控制字符旋轉:混合(預設)、直立、橫向 |
text-combine-upright | all / digits | 將連續數字/字母壓縮為一格寬 (直排時) |
IE 專有舊語法 (舊專案維護用)
.vertical-ie {
writing-mode: tb-rl; /* IE 私有 */
/* 或 */
layout-flow: vertical-ideographic; /* 更舊語法 */
/* 旋轉法 */
position:absolute;
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
}
現代標準寫法 (推薦)
.vertical {
writing-mode: vertical-rl; /* 從右往左,符合中日習慣 */
text-orientation: mixed; /* 漢字直立、英文旋轉 */
}
/* 若需英文也直立 */
.vertical-upright {
writing-mode: vertical-rl;
text-orientation: upright;
}
/* 數字兩位合一 */
.vertical-num {
writing-mode: vertical-rl;
text-combine-upright: digits 2;
}
完整範例
<div class="vertical">
<h2>直式排版範例</h2>
<p>春風又綠江南岸</p>
<p>2024 年 03 月</p>
</div>
瀏覽器支援
- writing-mode:Chrome 48+、Firefox 41+、Safari 10.1+、Edge 12+、IE 6+ (舊語法)
- text-orientation:Chrome 48+、Firefox 41+、Safari 10.1+、Edge 79+
- text-combine-upright:Chrome 48+、Firefox 48+、Safari 10.1+、Edge 79+
常見坑點
- 容器需有明確
height 或 max-height,否則直排內容會無限延伸。
- 混合語言時,
text-orientation:mixed 讓漢字直立、英文順時針旋轉 90°;若全直立用 upright。
- Flex/Grid 容器下
writing-mode 會影響主軸方向,佈局需配合調整。