两个DIV高度自适应方法(左右两个DIV高度一样)

html:
<div id="container"> <div id="leftSide"> <p>aaaa</p> <p>aaaa</p> </div> <div id="rightSide"> </div> </div> 1、负外补丁和正内补丁{margin-bottom:-(num)px;padding-bottom:(num)px;}相结合 #container{ 500px; margin:10px auto; overflow:hidden; font-size:14px; } #leftSide,#rightSide{ padding-bottom:9999px; margin-bottom:-9995px; color:#fff; } #leftSide{ 195px; float:left; background:blue; line-height:20px; padding-left:5px; } #rightSide{ 300px; float:left; background:green; line-height:20px; } 2、利用javascript脚本实现动态设置高度 var left = document.getElementById('leftSide'); var right = document.getElementById('rightSide'); if(left.offsetHeight>=right.offsetHeight){ right.style.height=left.offsetHeight+'px'; }else{ left.style.height=right.offsetHeight+'px'; }
原文地址:https://www.cnblogs.com/lcx90/p/4873602.html