2012-01-25 39 views
0

什麼是有兩個div的最好方式,左和對方的權利,其中一個規定的寬度,以及其他規定的高度:CSS - 一個框決定高度,其他寬度

CSS:

body 
{ 
    width:960px; 
    margin:auto; 
} 

.wholething 
{ 
    background-color:red; 
} 

.leftside 
{ 
    width:230px; 
    background-color:blue; 
} 
.rightside 
{ 
    height:640px; 
    background-color:green; 
} 

HTML:

<div class="wholething"> 
    <div class="leftside"> 
    </div> 
    <div class="rightside"> 
    </div> 
</div> 

結果看起來像一個藍色方塊230px寬,640像素高,一個綠色的盒子730像素,寬640像素高。然後,如果CSS更改爲寬度或高度,則兩個框都會相應地進行調整。請只添加到CSS;除非絕對必要,否則不要刪除css。

回答

0
body { 
    width:960px; 
    margin:auto; 
} 
.wholething { 
    background-color:red; 
    position: relative; 
    height: 640px; 
} 
.leftside { 
    position: absolute; 
    left: 0px; 
    top: 0px; 
    bottom: 0px; 
    width:230px; 
    background-color:blue; 
} 
.rightside { 
    position: absolute; 
    left: 230px; 
    right: 0px; 
    top: 0px; 
    bottom:0px; 
    background-color:green; 
} 

這會工作。但是,您需要更改第二個的left以匹配第一個的width

+0

左側框與此CSS的高度爲零。 – maverick

+0

它具有'0px'的'top'和'bottom',因此它將填充容器的高度... –

+0

http://jsfiddle.net/maverick/AaSfB/左側框具有零高度 – maverick

相關問題