16

How do I rotate text 90 degrees without using the style sheet? I have placed the following instruction in the header area of the page:

<style>
div.rotate-text {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
</style>

Then I placed the following around the paragraph in question.

<div id="rotate-text">
<p>My paragraph</p>
</div>

But its not working and hence my question.

Chris Gedge
  • 263
  • 1
  • 2
  • 6
  • 4
    Your css selector is wrong: it should be `div#rotate-text` and not `div.rotate-text`. `.` is for a class, `#` is for an id. – sjahan Nov 13 '17 at 09:37

5 Answers5

18

Here is a small visual example:

#rotate-text {
   width: 25px;
   transform: rotate(90deg);
}
<div id="rotate-text">
  <p>My paragraph</p>
</div>
sjahan
  • 5,720
  • 3
  • 19
  • 42
15

You can use css property writing-mode

writing-mode: vertical-rl

or

writing-mode: vertical-lr

Or using transform property: rotate

transform: rotate(90deg)
Freestyle09
  • 4,894
  • 8
  • 52
  • 83
  • 1
    ya, writing mode is what i wanted! I wanted to rotate the long headers in a table so they wouldn't take up as much space. – CpILL Mar 22 '22 at 00:48
5

you use of id in html code, so you must use of # in css.

Change:

div.rotate-text {

To:

div#rotate-text {

div#rotate-text {
  -webkit-transform: rotate(90deg);
  -moz-transform: rotate(90deg);
  -o-transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  transform: rotate(90deg);
  width: 100px;
  transform-origin: top left;
  margin: 50px;
}
<div id="rotate-text">
  <p>My paragraph</p>
</div>
Ehsan
  • 12,655
  • 3
  • 25
  • 44
4

Writing mode is better for text content, with transform: rotate() the text container still stays with the horizontal dimensions.

writing-mode: vertical-rl; //Rotate -90deg
writing-mode: vertical-lr; //Rotate 90deg
dvdmn
  • 6,456
  • 7
  • 44
  • 52
0

to get the text reading from the bottom up, use this:

#rotate-text {
   writing-mode: vertical-lr;
   transform: scale(-1, -1);
}
<div id="rotate-text">
  <p>My paragraph</p>
</div>
Hokascha
  • 1,709
  • 1
  • 23
  • 41