一、想必大家应该会碰到文字竖着排列,不知道大家采取的方法是什么,今天我分享一下我使用的吧!
这是我参考的css属性网址:writing-mode - CSS:层叠样式表 | MDN
writing-mode
writing-mode
它就是定义了文本水平或垂直排布以及在块级元素中文本的行进方向。
这些也是它的属性,
writing-mode: horizontal-tb;
writing-mode: vertical-rl;
writing-mode: vertical-lr;
对于左对齐(ltr
)文本,内容从左到右水平流动。对于右对齐(rtl
)文本,内容从右到左水平流动。下一水平行位于上一行下方。
对于左对齐(ltr
)文本,内容从上到下垂直流动,下一垂直行位于上一行左侧。对于右对齐(rtl
)文本,内容从下到上垂直流动,下一垂直行位于上一行右侧。
对于左对齐(ltr
)文本,内容从上到下垂直流动,下一垂直行位于上一行右侧。对于右对齐(rtl
)文本,内容从下到上垂直流动,下一垂直行位于上一行左侧。
官网举例:
<table>
<tr>
<th>值</th>
<th>竖排文本</th>
<th>横排文本(从左到右)</th>
<th>横排文本(从右到左)</th>
<th>混合文本</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>
.example.Text1 span,
.example.Text1 {
writing-mode: horizontal-tb;
}
.example.Text2 span,
.example.Text2 {
writing-mode: vertical-lr;
}
.example.Text3 span,
.example.Text3 {
writing-mode: vertical-rl;
}
.example.Text4 span,
.example.Text4 {
writing-mode: sideways-lr;
}
.example.Text5 span,
.example.Text5 {
writing-mode: sideways-rl;
}
运行可以看出效果!