CSS Layout instance: Upper Three rows, middle adaptive

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.