I am trying to achieve a table which has text rotated -90degrees. Up until now I have been using images of the text, however I was hoping to change this over to text.

There are a few problems I cannot seem to fix.
- Column 07 text overflows onto column 08.
- I cannot fix this with overflow:hidden; because I have to set the width and height both to 200px to get the correct shape.
- I have to set the width and height of the rotated text which does not make it very flexible to work with, and this also causes problem number 1.
- I have to set the margin to “0 -100px” because I have to set the width to 200px but once rotated its width is still 200px, which would make the table incredible large.
- If the font size is changed it no longer fits in the columns nicely.
- The fonts look terrible, and are hard to read. I figure this will work itself out in future updates of the browsers.
Here is a jsFiddle of it in action
http://jsfiddle.net/CoryMathews/ZWBHS/
I need it to work and have gotten it to the same point in IE7+, Chrome, FF, and Opera.
Any ideas on how to improve this method making it actually usable? Some of my ideas are:
-
I could calculate the widths, height, etc with some javascript on page load, this would solve problems 2 and 3 above but not 1. However I hate to rely on javascript for display.
-
Perhaps I am misusing the transform-origin that would give me better control. The number I am currently using “0 0” allows me to easily calculate the needed sizes.
This solution fixes some of your problems, but it’s not perfect:
whitespace: nowrapto disable text flowing to the next line.width: 1em. Columns are always wide enough for 1 line of vertical text. You can freely adjust the font size.Manually set the height of the table to fully display the rotated content (by -90 degrees). Hard-coding heights is not great, but there are advantages: no need for fixed widths and negative margins to counter the fixed widths / transform origins / relative positioning / JavaScript; text automatically snaps to bottom of column.
See 2.
This works in Firefox, Chrome, Opera, IE9+. Vertical text does not work on IE8 and earlier. I tried rotating the table using:
and the result looks horrible, so I added fallback style to display a simple horizontal table.