Vertical Centering in CSS with Unknown Height (ie7 compatible)
Posted in: Design
This article of jakpsatweb about vertical alignment is really the only solution I found out about this issue.
I take the Structural solution without Hack as reference, most of all becouse when an hack is not strictly neccesary it's better to avoid it.
Yuhu's code is great.
HTML:
CSS:
-
#outer {
-
height: 400px;
-
overflow: hidden;
-
position: relative;
-
}
-
-
#outer[id] {
-
display: table;
-
position: static;
-
}
-
-
#middle {
-
position: absolute;
-
top: 50%;
-
} /* for explorer only*/
-
-
#middle[id] {
-
display: table-cell;
-
vertical-align: middle;
-
position: static;
-
}
-
-
#inner {
-
position: relative;
-
top: -50%
-
} /* for explorer only */
-
-
/* optional: #inner[id] {position: static;} */
but it's not working on ie7, that catches [id] selectors but behaves as ie6.
so what?
according to css selectors we should write those css line more
CSS:
-
*:first-child+html #outer[id] {
-
position:relative
-
} /* for explorer 7 only */
-
-
*:first-child+html #middle[id] {
-
position: absolute;
-
display:block;
-
vertical-align:inherit;
-
top: 50%;
-
} /* for explorer 7 only */
-
-
/* optional: *:first-child+html #inner[id] {position: relative;} */
have fun :)
Return to: Vertical Centering in CSS with Unknown Height (ie7 compatible)
Social Web