两个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{ width:500px; margin:10px auto; overflow:hidden; font-size:14px; } #leftSide,#rightSide{ padding-bottom:9999px; margin-bottom:-9995px; color:#fff; } #leftSide{ width:195px; float:left; background:blue; line-height:20px; padding-left:5px; } #rightSide{ width: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'; }

 

posted @ 2015-10-13 09:44  猴--进化失败的程序猿  阅读(2569)  评论(0编辑  收藏  举报