有没有人知道如何使文本在div中垂直顶部对齐。
甚至SO都不允许我演示...我只想让字母在页面上垂直排成一条线,就像建筑物的故事一样。希望我不需要用图像来实现它。
有没有人知道如何使文本在div中垂直顶部对齐。
甚至SO都不允许我演示...我只想让字母在页面上垂直排成一条线,就像建筑物的故事一样。希望我不需要用图像来实现它。
writing-mode
CSS writing-mode
属性可以让您的文本垂直运行。
.traditional-vertical-writing
{
writing-mode: vertical-rl;
}
<p class="traditional-vertical-writing">
This text runs vertically.<br>
『只是』 ((but the thing is)),since Latin alphabets are not for vertical writing,
not only the lines but each of the non-vertical-writing letters also gets rotated.<br>
0123456789
</p>
text-orientation
如果你不想让非竖直书写的字母在竖直行中旋转,可以使用CSS text-orientation
属性。
.vertical-writing
{
writing-mode: vertical-rl;
text-orientation: upright;
}
<p class="vertical-writing">
This text runs vertically.<br>
『それに』 ((and in addition))、now you don't have to turn your head 90 degrees clockwise
to read these non-vertical-writing letters!<br>
0123456789
</p>
如果你需要在竖排文字的同时进行一些横向书写,可以考虑使用 text-combine-upright
。
为了让字母从上到下排列,但保持它们的正常方向,如下所示:
F
O
O
HTML:
<div class="toptobottom">letters</div>
CSS:
.toptobottom{
width: 0;
word-wrap: break-word;
}
word-wrap属性允许单词在中间被打断,因此这将使字母从上到下排列。它也被广泛支持:https://developer.mozilla.org/en-US/docs/CSS/word-wrap
Html:
<div class="bottomtotop">Hello!</div>
Css:
.bottomtotop { transform:rotate(270deg); }
NJCodeMonkey的回答很接近。
对我来说,我必须使用word-break
。它与word-wrap:break-word;
有一点不同。
所以它看起来像这样。
<div class="VerticalText">LongTextWithNoSpaces</div>
.VerticalText
{
width: 1px;
word-break: break-all;
}
<div style='width:12px'>a b c d</div>
vertical-lr
代替vertical-rl
可以使列从左到右排列。 - Αμηλωρε