CSS + DIV adaptive height layout

Source: Internet
Author: User

The head foot is fixed, and the middle area is adaptive to the content height. When the scroll bar is dragged, the foot always stays at the bottom.
The SolarDreamStudios solution gave me a good idea, but the key part was original. I always thought it would be better than the SolarDreamStudios solution, and they carefully read their code, but they seem to have made more effort in compatibility and are not tested.
A. Adaptive 100% in width
Structure code

The code is as follows: Copy code
<Body>
<Div id = "head"> head </div>
<Div id = "head_height"> </div>
<Div id = "middle"> </div>
<Div id = "foot_height"> </div>
<Div id = "foot"> foot </div>
</Body>

Presentation code

The code is as follows: Copy code
# Head {width: 100%; text-align: center; background: # FF9400; height: 100px; position: absolute; top: 0 ;}
# Head_height {height: 100px ;}
# Middle {margin: 20px ;}
# Foot {width: 100%; text-align: center; background: # f00; height: 100px; position: absolute; bottom: 0 ;}
* Html # foot {bottom:-1px ;}
# Foot_height {height: 100px ;}

B. Fixed width center
Structure code

The code is as follows: Copy code
<Body>
<Div id = "head">
<Div id = "head_content"> head </div>
</Div>
<Div id = "head_height"> </div>
<Div id = "middle"> </div>
<Div id = "foot_height"> </div>
<Div id = "foot">
<Div id = "foot_content"> foot </div>
</Div>
</Body>

Presentation code

The code is as follows: Copy code
# Head {width: 100%; text-align: center; position: absolute; top: 0; left: 0 ;}
# Head_content {line-height: 100px; width: 700px; margin: 0 auto; background: # FF9400; height: 100px ;}
# Head_height {height: 100px ;}
# Middle {margin: 20px ;}
# Foot {width: 100%; text-align: center; position: absolute; bottom: 0 ;}
* Html # foot {bottom:-1px ;}
# Foot_content {line-height: 100px; width: 700px; margin: 0 auto; background: # f00; height: 100px ;}
# Foot_height {height: 100px ;}

In IE6.0, FF1.5, and IE environments, sometimes the scroll bar is automatically displayed because of bugs (the same solution for SolarDreamStudios), and FF is the perfect result.

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.