Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical center a rotated div inside a div

Tags:

html

css

I don't get it ;-(

I want to center a div with a text contained in another div. The inner div is rotated by 90 degres. So far so good. My problem is that I can't get the inner div to align horizontal to the left of the outer div. How can this be done?

Here is the fiddle

HTML:

<div class="outer">
    <div class="inner">
        12345678901234567890
    </div>
</div>

CSS:

div {
    border: 1px solid red;    
}

.outer {
    position: absolute;
    top: 0px;
    height: 300px; 
    width: 30px;   
}

.inner {
    transform: translateX(-50%) translateY(-50%) rotate(90deg);
    margin-left: 10px;
    position: relative;
    top: 50%;
    text-align: center;
}

Painted

like image 812
dec Avatar asked Feb 11 '23 05:02

dec


1 Answers

Set the inner div to position:absolute too.

http://jsfiddle.net/r4vrf7pg/8/

div {
    border: 1px solid red;
}
.outer {
    position: absolute;
    top: 0px;
    height: 300px;
    width: 30px;
}
.inner {
    transform: translateX(-50%) translateY(-50%) rotate(90deg);
    margin-left: 10px;
    position: absolute;
    top: 50%;
    text-align: center;
}
<div class="outer">
    <div class="inner">
        12345678901234567890
    </div>
</div>
like image 141
Stickers Avatar answered Feb 13 '23 02:02

Stickers