Js实现两列div高度自适应

て烟熏妆下的殇ゞ 提交于 2020-03-21 15:54:09

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>两列div高度需要自适应的问题</title>
<style>
*{ margin:0px; padding:0px;}
#wrap{ width:776px; border:1px solid #f00; background: url(bg1.png) repeat; overflow:auto;}
#cloumn1{ float:left; width:298px; border:1px solid #ccc;}
#cloumn2{ float:right; width:474px; border:1px solid #00F;}
.clear{ clear:both;}
</style>

</head>

<body>
<div id="wrap">
     <div  id="cloumn1">
       <p>cloumn1</p>
       <p>cloumn1</p>
       <p>cloumn1</p>
     </div>
     <div  id="cloumn2">
      <p>cloumn2</p>
       <p>cloumn2</p>
       <p>cloumn2</p>
        <p>cloumn2</p>
         <p>cloumn2</p>
          <p>cloumn2</p>
          <p>cloumn2</p> <p>cloumn2</p>
    
     </div>
     <div class="clear"></div>
</div>
<script language="javascript" type="text/javascript">
 function $(id){return document.getElementById(id);}
 if($("cloumn1").clientHeight>$("cloumn2").clientHeigth)
 $("cloumn2").style.height=$("cloumn1").offsetHeight+"px";
 else
  $("cloumn1").style.height=$("cloumn2").offsetHeight+"px";
</script>
</body>
</html>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!