I have a block of a variable height in which I want to put another block with 100% height and vertical text (bottom-to-top direction) and stack it to the left side of the outer block. Is there a way to achieve it with CSS transforms but without width and height calculations in JS?
This is what I could get so far:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style type="text/css">
.block1 {
border: 4px solid #888;
height: 120px;
width: 200px;
}
.block2 {
height: 100%;
border: 4px solid red;
}
.msg {
display: inline-block;
white-space: nowrap;
font-family: Verdana;
font-size: 14pt;
-moz-transform: rotate(-90deg);
-moz-transform-origin: center center;
-webkit-transform: rotate(-90deg);
-webkit-transform-origin: center center;
-ms-transform: rotate(-90deg);
-ms-transform-origin: center center;
}
</style>
</head>
<body>
<div class="block1">
<table class="block2">
<tr>
<td>
<div class="msg">Hi there!</div>
</td>
</tr>
</table>
</div>
</body>
</html>
You can see that the inner block's computed width is the same as the text width before rotation.
UPDATE:
Here is the picture of what I want to get in the end:
It's a horizontal stripe with items stacked to its left side, and with a vertical header block. Stripe's height is variable, so items should adapt and the header's text should remain centered.
The best I could come up with is this: http://jsfiddle.net/EwgtT/
The variable height of block1 won't be a problem, but the variable height of your message is; it will always start at the bottom.
Edit: Updated, so it works well in FF and IE: http://jsfiddle.net/EwgtT/2/
I came up with this:
You can see it here: http://pastehtml.com/view/c0hl7zxci.html
I believe you were only using a
<table>
because it seemed to be the easiest way to achieve what you were looking for, so I cut it out of the equation and used semantic HTML instead. If there was another reason, I apologize in advance and you should be able to port the styles over to use a<table>
instead.See the jsFiddle demo to view the code in action. Or, continue on to the code:
HTML
CSS
How it works
The
<header>
is set to the height of.wrapper
and has it'swidth
set to2em
(value ofline-height
for the<h1>
). Then, the<h1>
is vertically aligned (withtop:0;bottom:0;height:2em;margin:auto;
[2em
is also fromline-height
]). Once the<h1>
is vertically aligned, it is rotated counter-clockwise 90 degrees by the middle of its left side. In order to make the<h1>
visible again, it is translated50%
vertically (to pull it back onto the screen horizontally) and-50%
horizontally (to vertically align it). And yes, the wording is correct--everything just gets confusing once you rotate by [-]90 degrees ;)Gotchas
<h1>
. In this case, only 1 line is supported.height
of.wrapper
will be hidden.After looking at the transform styles more thoroughly, it doesn't appear so. You would need to know the precise height of the outter
div
.