Upper and lower three lines of layout, up and down high, the middle bar adaptive browser height, and content vertically centered.
Firefox 2.0/win ie 6/win ie 7/opera 8.5 cn/win Safari test passed.
For non-IE kernel browsers, display:table, Display:table-row, and Display:table-cell are used to simulate the form's representation.
Outermost #box {display:table}, height 100%, its child layer #header/#main/#footer为 {display:table-row}, so you can simulate the row effect of the table, up and down high, then the middle of the high level of adaptive height.
#wrap层为 {Display:table-cell;} Simulates a cell, so you can set {Vertical-align:middle;}, centered vertically.
Because win IE does not support {display:table}, it can only be implemented in a positioning manner. <!--[if Ie]> is set for IE.
| <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <meta http-equiv=" Content-type " Content= "text/html; charset=gb2312 "/> <title> lower three line layout, up and down, middle bar adaptive browser height, and content vertically centered </title> <style type=" Text/css "> * { margin:0; padding:0; } HTML, Body, #box { height:100%; font:small/1.5 "Song Body", serif; } Body { Text-align:center; } #box { Text-align:left; Background: #666; Display:table; width:80%; margin:0 Auto; Position:relative; } #box > div { Display:table-row; } #header, #footer { background: #fcc; height:50px; } #main { background: #ccf; } #main #wrap { Display:table-cell; Background: #ffc; Vertical-align:middle; } #text { Text-align:center; } </style> <!--[if ie]> <style type= "Text/css" > #header, #footer { WI dth:100%; Z-index:3; Position:absolute; } #footer { bottom:0; } #main { height:100%; Z-index:1; position:relative; } #main #wrap { Position:absolute; top:50%; width:100%; Text-align:left; } #main #text { position:relative; width:100%; top:-50%; Background: #ccc; } </style> <! [endif]-->
<body> <div id= "box" > <div id= "Header" >header</div> <div id= "Main" > <div id= "Wrap" > <div id= "Text" > <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> <p> content </p> </div> </div> </div> <div id= "Footer" >footer</div> </div> </body>
|