About div Adaptive height/left-right height adaptive consistent JS code _javascript skills

Source: Internet
Author: User
In the use of Div and CSS for Web page layout, Div's Adaptive height and adaptive width is a very common problem.
To ensure the overall beauty of the page, you need to keep the height/width of two or more layers consistent.

Right and left adaptive highly consistent Jquery
Copy Code code as follows:

<div style= "width:300px;" >
<div id= "left" style= "Float:left;background-color:blue;" >1<br/>3<br/>5<br/></div>
<div id= "Right" style= "float:right;background-color:red;" >2</div>
</div>
<script type= "Text/javascript" src= "Http://jt.875.cn/js/jquery.js" ></script>
<script type= "Text/javascript" >
$ (function () {
var heightleft= $ ("#Left"). Height ();
var heightright= $ ("#Right"). Height ();
if (Heightleft > Heightright)
{
$ ("#Right"). Height (heightleft);
}
Else
{
$ ("#Left"). Height (heightright);
}
})
</script>

div Height Adaptive Screen js
Copy Code code as follows:

<div id= "Top" style= "height=" 200px; ></div>
<div id= "box" >dsafsafsafsafsafdsa</div>
<script>
window.onload= function () {
function auto_height ()
{
//var h= document.documentelement.clientheight-200;
//var high = document.getElementById ("box");
//high.style.height=h+ "px";
document.getElementById ("box"). style.height=document.documentelement.clientheight-200+ "px";
}
Auto_height ();
Onresize=auto_height;
}
</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.