1
As of the writing of this article (early 2011), the specifications for CSS3 are incomplete. So, this article will focus only on CSS that can be used now to create vertical text in most modern browsers. Though most of the code we will use are proprietary properties, they are preparatory to CSS3.
Internet Explorer 9 was not fully developed when this article was written, so though this browser may support CSS3 properties in the form of -ms-transform, it was not ready for widespread use to rotate or make vertical text, and will not be covered in this article.
I will create a container element and a stylized element to rotate. The block of code below is not necessary to rotate text.
This code is for clarity only. It is not necessary to rotate text.
|
Our Element |
If you are using IE to view this page, the following examples will not appear correctly.
Below are the CSS properties to rotate an element. First, we will use rotation to create vertical text for Mozilla, Webkit, and Opera.
These will rotate our element 90° clockwise.
|
These will rotate our element 270° clockwise.
|
Our Element
→ |
Element at 90° |
Our Element
→ |
Element at 270° |
The element above was rotated 90° clockwise, but it doesn't seemed to be aligned to anything. That's because the origin of rotation is exactly in the middle of the element. The transform-origin property can fix this by telling the element where to rotate from.
These will set the rotation from the top left.
|
These will set the rotation from the top right.
|
Our Element
→
|
Element at 90° |
Our Element
→
|
Element at 270° |
The above result may be just what you want. If so, that's great! But to align your element back inside the container, use position: relative and left or right to push the element into place. Notice the element offset is equal to its own height plus border.
Push element left equal to its height.
|
Push element right equal to its height.
|
Our Element
→
|
Element at 90° |
Our Element
→
|
Element at 270° |
The next step is to create the same effect in Internet Explorer. This is now covered in our CSS article, Vertical Text in Internet Explorer.
We realize that was a long tutorial on rotated and vertical text so you might have some questions. As a Shenzhen, China web design company we make it a point to interact with development community as much as possible. So if you have a question about rotated or vertical text leave us a comment and we will see if we can answer it for you.
Let's get into contact so you learn more about us and we can create solutions for you!