Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make text run top-to-bottom in CSS?

Does anyone know how to make text align top-to-bottom in a div.

SO won't even let me demonstrate it . . . I just want the letters to stack on top of each other in a vertical line down the page like the stories of a building. Was hoping I didn't need to do it with an image.

like image 746
Kenneth Johns Avatar asked Feb 04 '09 04:02

Kenneth Johns


People also ask

How do I center text on top and bottom in CSS?

To just center the text inside an element, use text-align: center; This text is centered.

How do you change the text direction in CSS?

To achieve a vertical text orientation, set the writing mode property to vertical-lr(or vertical-rl) and set text-orientation to upright.


2 Answers

Having your text run along vertical lines WITHOUT HACKS

writing-mode

CSS writing-mode attribute lets your text run vertically.

.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

If you don't want non-vertical-writing letters to rotate themselves in vertical lines, you may use CSS text-orientation attribute as well.

.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>

And if you’re to do some tate-chuu-yoko[1][2][3] (a bit of horizontal writing while writing vertically),

consider using text-combine-upright.

like image 184
Константин Ван Avatar answered Sep 24 '22 22:09

Константин Ван


To make the letters top-to-bottom while keeping their normal orientation, like this:

F

O

O

HTML:

<div class="toptobottom">letters</div>

CSS:

.toptobottom{
  width: 0;
  word-wrap: break-word;
}

word-wrap allows words to be broken in the middle, so this will make the letters top-to-bottom. It's also really well supported: https://developer.mozilla.org/en-US/docs/CSS/word-wrap

like image 41
NJCodeMonkey Avatar answered Sep 20 '22 22:09

NJCodeMonkey