CSS multiple div floating float height adaptive two methods

Source: Internet
Author: User
CSS multiple div float side-by, height adaptive (self-increment)

When using div + CSS for a three-column or two-column layout, it's easy to make the two columns (or three columns) the same height, but using a div + CSS makes it more cumbersome. As a general rule, most of the methods used to fill or JS script with background map are of the same height.

Method One: Pure CSS solution ("Hide container Overflow" and "positive patch" and "negative external patch" combined method):

<style type= "Text/css" ><!--#wrap {overflow:hidden;} #sidebar_left, #sidebar_right {padding-bottom:100000px;margin-bottom:-100000px;} --></style><div id= "wrap" style= "width:300px; Background: #FFFF00; " >    <div id= "Sidebar_left" style= "float:left;width:100px; height:1000px; 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; height:500px; background: #0000FF;" >Right</div></div>

Method Two: JS solution (thinking, this method is not recommended):

<script>var A=math.max (document.getElementById ("left"). OffsetHeight,  document.getElementById ("center"). Offsetheight,document.getelementbyid ("right"). offsetheight); Gets the maximum height of the 3 div document.getElementById ("left"). Style.height = a + "px";d Ocument.getelementbyid ("center"). Style.height = a + "px";d Ocument.getelementbyid ("right"). Style.height = a + "px"; </script> 

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.