Div + CSS highly adaptive solution

Source: Internet
Author: User

The adaptive height problem is that when three or two columns are laid out using Div + CSS, you do not know the specific height beforehand. You can only increase or decrease the adaptive height based on the content, to make the two (or three) columns have the same height, it is easy to use Table, but it is quite troublesome to use Div + CSS. According to the general practice, most of them use the background image filling or JS script method to make the height the same, but these are not the best methods. I think...
The following describes how to use a combination of "hide container overflow", "positive patch", and "negative Patch".
Main code:

The code is as follows: Copy code
# Wrap {overflow: hidden;}/* External container */
# Sidebar_left, # sidebar_right {padding-bottom: 100000px; margin-bottom:-100000px;}/* column */

Complete example code:

The code is as follows: Copy code
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/>
<Title> Div + CSS Example, Wayhome's Blog </title>
<Style type = "text/css">
<! --
# Wrap {overflow: hidden ;}
# Sidebar_left, # sidebar_right {padding-bottom: 100000px; margin-bottom:-100000px ;}
-->
</Style> <Body>
<Div id = "wrap" style = "width: 300px; background: # FFFF00;">
<Div id = "sidebar_left" style = "float: left; width: 100px; background: # FF0000;"> Left </div>
<Div id = "sidebar_mid" style = "float: left; width: 100px; background: #666;">
Middle <br/>
Middle <br/>
Middle <br/>
Middle <br/>
Middle <br/>
Middle <br/>
Middle <br/>
Middle <br/>
Middle <br/>
</Div>
<Div id = "sidebar_right" style = "float: right; width: 100px; background: # 0000FF;"> Right </div>
</Div>
</Body>
</Html>

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.