| 值 | 書寫方向 | 塊流向 | 內聯流向 | 適用場景 |
|---|---|---|---|---|
horizontal-tb | 水平、從上到下 | 垂直向下 | 水平向右 (LTR) | 默認,拉丁文、中文橫排 |
vertical-rl | 垂直、從右到左 | 水平向左 | 垂直向下 | 中文傳統豎排、日文漢字 |
vertical-lr | 垂直、從左到右 | 水平向右 | 垂直向下 | 蒙古文、某些設計排版 |
sideways-rl | 垂直、字符順時針旋轉 90° | 水平向左 | 垂直向下 | 拉丁文強制豎排 |
sideways-lr | 垂直、字符逆時針旋轉 90° | 水平向右 | 垂直向下 | 拉丁文強制豎排 |
.vertical-text {
writing-mode: vertical-rl;
text-orientation: mixed; /* 默認:漢字直立,拉丁字母旋轉 90° */
text-orientation: upright; /* 強制所有字符直立 (適合全中文) */
text-orientation: sideways; /* 強制所有字符旋轉 (適合拉丁文) */
}
.vertical-classic {
writing-mode: vertical-rl;
width: 1.2em; /* 僅容納一個漢字寬度,強制換行形成豎列 */
line-height: 1.5; /* 字符間距 */
text-align: center; /* 水平居中 (在垂直流中是塊方向居中) */
height: 200px; /* 固定高度容器 */
overflow-y: auto; /* 內容過長可滾動 */
}
.vertical-layout {
writing-mode: vertical-rl;
text-orientation: upright;
/* 邏輯屬性:自適應書寫模式 */
inline-size: 300px; /* 塊方向尺寸 (垂直流中是高度) */
block-size: auto; /* 內聯方向尺寸 (垂直流中是寬度) */
padding-block: 24px; /* 塊方向內邊距 (上下) */
padding-inline: 16px; /* 內聯方向內邊距 (左右) */
margin-block: 16px; /* 塊方向外邊距 */
border-block-start: 2px solid var(--color-primary); /* 頂部邊框 */
/* 字體優化 */
font-feature-settings: "vert" 1, "vrt2" 1; /* OpenType 垂直替換特性 */
font-variant: upright; /* 等同 text-orientation: upright */
}
@container (max-width: 400px) {
.vertical-layout {
writing-mode: horizontal-tb; /* 窄容器自動切回橫排 */
inline-size: auto;
block-size: auto;
}
}
<article class="poem-card">
<header class="poem-header">
<h2 class="poem-title">靜夜思</h2>
<p class="poem-author">李白</p>
</header>
<div class="poem-content">
<p>床前明月光</p>
<p>疑是地上霜</p>
<p>舉頭望明月</p>
<p>低頭思故鄉</p>
</div>
</article>
.poem-card {
writing-mode: vertical-rl;
text-orientation: upright;
inline-size: 280px;
padding-block: 32px;
padding-inline: 24px;
background: linear-gradient(180deg, #fdf6e3 0%, #f5e6c8 100%);
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
font-family: "Noto Serif SC", "Source Han Serif", serif;
font-size: 1.125rem;
line-height: 2;
color: #3d2b1f;
}
.poem-header {
margin-block-end: 24px;
padding-block-end: 16px;
border-block-end: 1px dashed #d4b896;
text-align: center; /* 在垂直流中 = 塊方向居中 */
}
.poem-title { font-size: 1.5em; font-weight: 600; margin-block-end: 8px; }
.poem-author { font-size: 0.875em; color: #8b6d4a; }
.poem-content p { margin: 0; text-indent: 0; } /* 詩歌無需首行縮進 */
.mixed-layout {
display: grid;
grid-template-columns: auto 1fr;
gap: 24px;
align-items: start;
}
.mixed-layout .label {
writing-mode: horizontal-tb; /* 標題橫向 */
font-weight: 600;
font-size: 0.875rem;
color: var(--color-text-secondary);
white-space: nowrap;
}
.mixed-layout .content {
writing-mode: vertical-rl;
text-orientation: upright;
inline-size: 200px;
font-size: 1rem;
line-height: 1.8;
}
width/height、margin-top/bottom、border-left/right 等物理屬性含義互換,強制使用邏輯屬性 (inline-size/block-size, margin-block/inline, border-block/inline-start/end)align-items: start 或 stretch,避免交叉軸對齊異常<input>、<textarea> 在垂直書寫模式下表現不一,建議容器橫排、內部控件獨立 writing-mode: horizontal-tboverflow-y 是塊方向滾動 (視覺上左右),overflow-x 是內聯方向 (視覺上上下)user-select: none,編輯場景建議提供橫排編輯模式writing-mode:全現代瀏覽器支持 (IE11+ 需 -ms- 前綴)text-orientation:Chrome 48+, Firefox 41+, Safari 15.4+, Edge 79+font-feature-settings: "vert":依賴字體支持,Noto Serif SC / Source Han Serif 完美支持邏輯屬性:全現代瀏覽器支持垂直排版不再是「黑科技」,而是現代 CSS 書寫模式規範的標準能力。結合邏輯屬性、容器查詢、OpenType 特性,可構建優雅、響應式、無障礙的中文傳統排版體驗。