Kevin
Kevin

Reputation: 111

Containing element not expanding vertically when content has rotated text

I have a table with some th tags that contain text that is rotated via CSS. The problem I have is that the th is not expanding vertically with the content. Here is a basic example of the markup I have:

HTML:

<table>
    <thead>
        <th>
            <div class="rotated-text">Some Text</div>
        </th>
        <th>
            <div class="rotated-text">Some More Text</div>
        </th>
        <th>
            <div class="rotated-text">Even More Text</div>
        </th>
    </thead>
</table>

CSS:

.rotated-text {
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
    -webkit-transform: rotate(-90deg); 
    -moz-transform: rotate(-90deg); 
}

Example: http://jsfiddle.net/UPFkX/1/

Upvotes: 2

Views: 1252

Answers (2)

Juan Rangel
Juan Rangel

Reputation: 1793

A few edits to your code.

Remove the div and add the class"rotated-text" to your th. add this javascript
$(".verticalTableHeader").each(function(){$(this).height($(this).width())})

Make sure your page calls on jQuery.

http://jsfiddle.net/UPFkX/3/

Upvotes: 1

Fabian Lauer
Fabian Lauer

Reputation: 511

The containing elements can not expand, as css transformations (and IE filters) do not influence the box model.

To qoute Marco Miltenburg:

If I'm not mistaken elements are part of the normal flow or are floated as if they are not transformed. Once their position has been established, then the transformation or transition is performed. The transformation or transition will not have any influence on the document flow or any floating anymore.

You can find his answer to a similar question on SO here.

Actually, the width property of the transformed element will actually change it's visible "height" now, and the height property will change it's visible "width". In short:

With css transformations, it's the apperance that's being transformed, not the element itself or it's "influence" on the document flow.

What might help you though (case dependent):

Set the height property of each transformed element to it's width in pixels. That will influence their containers height just the way you want it.

EDIT:

As Juan Rangel said in his answer, you could go for javascript to solve the problem. I totally agree on that - what he would do with jquery is the same thing I was talking about above. If you can not tell how tall the transformed elements will be, that might even be the better solution, but keep the (small amout of) clients in mind that don't allow you to use javascript. Anyways, you'll have to compromise unfortunately.

Upvotes: 7

Related Questions