This looks like it should be possible with the following:
.verticalText { /* IE-only DX filter */ writing-mode: tb-rl; filter: flipv fliph; /* Safari/Chrome function */ -webkit-transform: rotate(270deg); /* works in latest FX builds */ -moz-transform: rotate(270deg); }
This works in IE.
It goes wrong in a bizarre way in Safari, Chrome and FX - the cell's size is calculated before the text is rotated!
Here is a demo: http://jsfiddle.net/HSKws/
I'm using dynamic images as a workaround, although that also has its problems. I'm happy with that as a fall-back, but it seems like there should be a way to make this CSS work - it's almost there.
Anyone know a way to make the cells fit the content after the transform has been applied?
Rotate text can be done by using the rotate() function. We can rotate the text in clockwise and anti-clockwise direction. The rotate function can also rotate HTML elements as well.
The first trick is to use writing-mode: vertical-lr to get the text to run vertically. By itself, the text runs top to bottom, but we want it to run bottom to top, so we spin it around it with the transform: rotate(180deg) .
The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements.
If what you are looking for is a way to set type vertically, you're best bet is probably CSS writing-mode . The rotation property of Internet Explorer's BasicImage filter can accept one of four values: 0, 1, 2, or 3 which will rotate the element 0, 90, 180 or 270 degrees respectively.
‘transform’ alters the orientation of the entire element you declare it on, not the text content inside it. It's more like IE's ‘matrix’ property than ‘writing-mode’.
Crucially, transforming an element doesn't change how its content size is calculated (or how its parent's layout is affected by that size). CSS's algorithms for vertical and horizontal sizing are different and difficult enough to get right to being with; there's no real consistent way they could accomodate content with arbitrary rotation. So ‘transform’ is like using ‘position: relative’: it changes where the content is rendered, but not anything to do with layout size.
So if you want to include one in a table you'll need to set the cell's ‘height’ explicitly to accomodate the expected rotated ‘width’. If you don't know that in advance you could potentially hack it up with JavaScript, perhaps.
FWIW: for me on Fx3.1b3 the span is also rotated like the others. However on Windows with its horizontal-only anti-aliasing (ClearType) the rendering doesn't look great... a well-rendered image could come out considerably better.
It's possible using inline SVG in a XHTML document (I only tested Safari and Firefox):
<html xmlns="http://www.w3.org/1999/xhtml"> <body> <table border="1"> <tr> <td> </td> <td> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="150"> <text id="thetext" transform="rotate(270, 12, 0) translate(-140,0)">Example column header</text> </svg> </td> <td> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="150"> <text id="thetext" transform="rotate(270, 12, 0) translate(-140,0)">Example column header</text> </svg> </td> <td> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="150"> <text id="thetext" transform="rotate(270, 12, 0) translate(-140,0)">Example column header</text> </svg> </td> </tr> <tr> <td>Example row header</td> <td>1</td> <td>2</td> <td>3</td> </tr> </table> </body> </html>
Unfortunately, you do have to explicitly set the width and height of your table cells and the translation of the text rendered using SVG. Also, the file extension must be xhtml
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With