div 兩列自動對齊

function alignHeight(eleA,eleB){
  if(!document.getElementById(eleA)){return false;}
  if(!document.getElementById(eleB)){return false;}
  var heightA = document.getElementById(eleA).clientHeight;
  var heightB = document.getElementById(eleB).clientHeight;
  if(heightA > heightB){
    document.getElementById(eleB).style.height = heightA + "px";
    document.getElementById(eleA).style.height = heightA + "px";
  }else{
    document.getElementById(eleA).style.height = heightB + "px";
    document.getElementById(eleB).style.height = heightB + "px";
  }
}
window.onload =
function z_align(){
  alignHeight("left","right"); //只需將需要對齊的兩個模塊的id寫在此處即可。
//alignHeight("AAA","BBB") 可依此連續多組。
}
#box{width:1000px;}
#box #left{float:left width:300px;}
#box #right{float:left; width:100px;}
<div id="box">
<div id="left">測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容</div>
<div id="right">我要跟他對齊</div>
</div>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章