2011-07-21 127 views
-1

可能重複:
Simple 2 column div layout
2 column layout in CSS2列DIV佈局

我想建立一個2列DIV佈局。其中一列應該右對齊並且自動調整大小,另一列應該填滿剩下的剩餘空間。

+3

有趣。你有什麼嘗試? – Trevor

+0

...並且當您將此問題的標題鍵入Stack Overflow時,您是否看不到任何相關問題? – Phrogz

+1

[Simple 2 column div layout](http://stackoverflow.com/questions/6748178/simple-2-column-div-layout)或[CSS中的2列布局]的副本(http://stackoverflow.com/questions/144375/2-column-layout-in-css)或[DIV only two-column CSS layout](http://stackoverflow.com/questions/3432304/div-only-two-column-css-layout)或(本網站上已有大量其他相關問題)。 – Phrogz

回答

5

想要這樣http://jsfiddle.net/UNgcd/2/

HTML:

<div class='wrap'> 
    <div class='right'> 
     <p>some text goes here for auto width</p> 
    </div> 
    <div class='left'> 
     <p>this takes up remaining space to the left</p> 
    </div> 
</div> 

CSS:

.right { 
    background-color: red; 
    float: right; 
    width: auto; 
} 

.left { 
    background-color: yellow; 
    overflow: hidden; 
} 
+0

爲什麼爲'左'列設置'margin-right'不起作用? – Cornel

+0

適用於我http://jsfiddle.net/UNgcd/3/ – ngen

+0

適用於Google Chrome和FF,但不適用於IE。 – Cornel

1

HTML:

<div id="right">Auto sized right div</div> 
<div id="left">Auto filling left div</div> 

CSS:

#left{ 
    overflow: hidden; 
} 

#right{ 
    float: right; 
} 
+0

http://jsfiddle.net/Paulpro/aCC7b/ – Paulpro