Rotating text using CSS

Posted by Renso on Geeks with Blogs See other posts from Geeks with Blogs or by Renso
Published on Fri, 24 Jun 2011 09:32:27 GMT Indexed on 2011/06/24 16:23 UTC
Read the original article Hit count: 256

Filed under:

Goal:

Rotating text using css only.

How:

Surprisingly IE supports this feature rather well. You could use property filters in IE, but since this is only supported on IE browsers, I would not recommend it.

CSS3, still in proposal state, has a "writing-mode" property for doing this. It has been part of IE's browser engine since IE5.5. Now that it is part of the CSS3 draft specification, would be the best way to implement this going forward.

Webkit based browsers; Firefox 3.5+, Opera 11 and IE9 implement this feature differently by utilizing the transform property.

Without using third-party JavaScript or CSS properties, we can use the CSS3 "writing-mode" property, supported from IE5.5 up to IE8, the latter adding addition formatting options through -ms extensions.

<style type="text/css">

.rightToLeft{ writing-mode: tb-rl; }

</style>

<p class="rightToLeft">This is my text</p>

This will rotate the text 90 degrees, starting from the right to the left.

Here are all the options:

·         lr-tb – Default value, left to right, top to bottom

·         rl-tb – Right to left, top to bottom

·         tb-rl – Vertically; top to bottom, right to left

·         bt-rl – Vertically; bottom to top, right to left

·         tb-lr – Available in IE8+: -ms-writing-mode; top to bottom, left to right

·         bt-lr – Bottom to top, left to right

·         lr-bt – Left to right, bottom to top

What about Firefox, Safari, etc.? The following techniques need to be used on Webkit browsers like Firefox, Opera 11, Google Chrome and IE9. These browsers require their proprietary vendor extensions: -moz-, -webkit-, -o- and -ms-.

  • -webkit-transform: rotate(90deg);   
  • -moz-transform: rotate(90deg);
  • -ms-transform: rotate(90deg);
  • -o-transform: rotate(90deg);
  • transform: rotate(90deg);

 

 

© Geeks with Blogs or respective owner