Implicitly synchronize the heights of two divs, and implicitly synchronize the heights of Divs.

Source: Internet
Author: User

Implicitly synchronize the heights of two divs, and implicitly synchronize the heights of Divs.

In the past, I encountered two adjacent blocks with the same height, but the contents were not scheduled. I used to encapsulate these two blocks in TD to implement them, but today I saw someone using JS to implement this in CSDN. I tried it.
Http://topic.csdn.net/u/20080617/18/cfc9201a-613f-432e-a828-3f3808b9553d.html? Seed = 553780558

The following code is used for implementation. (although I personally think this code is not very practical, it is also a solution in a specific scenario ). the following code shows that JQuery is very convenient to use. I really don't know how to retrieve the height of an element when using native objects. I use document. getElementById ("rightbar "). style. the height value is auto.



First in: http://www.xfuse.cn



<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> untitled document </title>


<Script language = "JavaScript" src = "http://code.jquery.com/jquery-latest.js"> </SCRIPT>


<Script>


</Script>
</Head>

<Body>
<Div>


<Div id = main>
Dynamically generated content, highly variable <br>
Dynamically generated content, highly variable <br>
Dynamically generated content, highly variable <br>
Dynamically generated content, highly variable <br>
Dynamically generated content, highly variable <br>
Dynamically generated content, highly variable <br>

</Div>
<Div id = rightbar>
Right sidebar with less content than main
</Div>
</Div>
<Script language = "javascript">
Window. onload = function (){

Var he = $ ('# main'). height ();

$ ('# Rightbar'). height (he );

};
</Script>
</Html>


How can I use the CSS + DIV style to synchronize the height of the left and right divs?

If IE6 is not considered, use min-height :? Px; IE6 does not support this

How does DIV + CSS make the height of the left and right divs consistent?

The most typical two-column adaptive height CSS code is passed in IE5, 6, 7, and FF tests. Hope to be useful to you:

Body {
Padding: 0;
Margin: 0;
Color: #333/* #0d7206 */;
Font-size: 14.7px;
Font-family: Arial, Helvetica, sans-serif;
Line-height: 140%;
Text-align: center;
Background: url(body_bg.jpg) # c8fdcc repeat-x top left;
}
# Pagebody {
Width: 760px;
Margin: 10px auto;
Overflow: hidden;
}
# Sidebar {
Border-right: 1px #009900 dotted;
Width: 199px;
Float: left;
Background: url(l_bg_contbox.png) # FFF repeat-y left;
Text-align: left;
}
# Mainbody {
Width: 560px;
Float: left;
Background: url(r_bg_contbox.png)/* # f6f6f6 */# fff repeat-y right;
Text-align: left;
}
/* Easy clearing */
# Pagebody: after
{
Content: '[do not leave it is not real]';
Display: block;
Height: 0;
Clear: both;
Visibility: hidden;
}
# Pagebody
{
Display: inline-block;
}
/*\*/
# Pagebody
{
Display: block;
}
/* End easy clearing */
/*\*/
# Sidebar, # mainbody
{
Padding-bottom: 32767px! Important;
Margin-bottom:-32767px! Important;
}
@ Media all and (min-width: 0px ){
# Sidebar, # mainbody
{
Padding-bottom: 0! Important;
Margin-bottom: 0! Important;
}
# Sidebar: before, # mainbody: before
{
Content: '[do not leave it is not real]';
Display: block;
Background: inherit;
Padding-top: 32767px! Important;
Margin-bottom:-32767px! Important;
Height: 0;
}
}
/**/... The remaining full text>

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.