CSS Layout Kinky tricks-Multiple columns equal height

Source: Internet
Author: User

What is the equal height layout?

First look at a case:

The main content of the page in is two-column structure, the left column is used to navigate, and the right column is used to display the content. We see that they have a common border and a dividing line in the middle, and the height of the left and right columns is not fixed. In this case, the height of the two columns needs to be consistent, the left height increases, the right side increases, the right height increases, the left side is also increased, otherwise the "fault" effect will occur. Here, the high layout is to maintain the integrity of the border lines, in some places may be to maintain the integrity of the background, to achieve the overall consistency is not missing effect.

Layout scenarios

There are several different approaches to high-level layouts, but so far I think the best and easiest browser compatibility should be the padding compensation method. First, set the Padding-bottom of the column to a value that is large enough, and then set the Margin-bottom of the column to a negative number that is offset by the positive value of the previous Padding-bottom, and the parent container setting is out of the hidden The height of the parent container is still the height of the column in the Padding-bottom when it is not set, and when any column in it has a height increase, the height of the parent container is propped up to the height of the highest column in it. Other columns that are shorter than this list use their padding-bottom to compensate for this part of the height difference. Because the background is can be used in padding occupied space, and the border is also following the padding change, so the successful completion of a fake.

Code

Let's take a look at the situation where there are no high layouts

Effect:

Then we apply the equal-height layout:

The effect is as follows:

When you do something, the value of Padding-bottom depends on the actual situation of your project, and if you're unsure, it doesn't matter if you make it bigger.

The final code:

12345678910111213141516171819202122232425262728 <!DOCTYPEhtml><html><head><metacharset="utf-8" /><title>高度自适应布局</title><style>body{ padding:0; margin:0; color:#f00;}.container{ margin:0 auto; width:600px; border:3px solid #00C;    overflow:hidden; /*这个超出隐藏的声明在IE6里不写也是可以的*/}.left{ float:left; width:150px; background:#B0B0B0;    padding-bottom:2000px;    margin-bottom:-2000px;}.right{ float:left; width:450px; background:#6CC;   padding-bottom:2000px;   margin-bottom:-2000px;}</style></head><body><divclass="container">    <divclass="left">我是left</div>    <divclass="right">我是right<br><br><br>现在我的高度比left高,但left用它的padding-bottom补偿了这部分高度</div>    <divstyle="clear:both"></div></div></body></html>

CSS Layout Kinky tricks-Multiple columns equal height

Related Article

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.