css| skills | Solve div column height self-adaptive methods There are a number of ways, here are three of the most commonly used methods for everyone (the following examples are the parent main, Divleft, divright, for example).
1, the use of "clear:both" background to fill (recommended!!! )
This is the most widely used approach, and I've been using this method to solve the div column height self adaptation problem. Three lines of two column layout, the main content on the right, page width 780px, left column 240px, right column 540px.
Add the following code to the <body> (assuming the divright is relatively high):
<script language= "JavaScript" >
document.getElementById "Divleft"). Style.height=document.getelementbyid "Divright"). scrollheight+ "px"
</script>
Advantages:Code Super Simple
Disadvantages:This method is relatively passive to determine that the height of a column is always relatively high.
This method can better solve the problem of the same column height. Three lines of two column layout, the main content on the left, Web page width of 780px, left column 540px, right column 240px.
<div id= "Main" >
<div id= "Divleft" >
<div id= "Divright" ></div>
</div>
</div>
Perhaps just contact the Web standards's friends do not understand this method, now blank analysis:
A
[B][c]
A contained c,c in the upper structure contains B. When the height of B is the highest, then a and C will inherit the height of B, and if A and B positions coincide, the background of B will be displayed, and when C is the highest height, then a inherits the height of C, and if A and B overlap, the background of a is displayed. This shows that the div column height is the same regardless of the highest or highest c.
Advantages:Both have the advantage of the first method and are slightly simpler than the code for the first method.
Disadvantages:The overall structure can only be left-aligned.
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.