2011-10-09 34 views
0

There is a way to do it using absolute positioning.如何將CSS列擴展到可用空間?

我有一個雙列布局。左列是固定的200px寬度加上30px的左邊距。右欄包含內容,並應展開以適應可用空間。

我已經完成了定位每個列使用絕對位置和拉伸右列使用右:0px,它會觸及右邊緣。當使用float:left來定義列時,有沒有辦法達到同樣的效果?到目前爲止,該列僅擴展以適合其內容的寬度。

如果我可以使用Compass/Sass(但我不想依賴像Blueprint這樣的框架,因爲佈局非常簡單)就可以做到這一點。

回答

4

@Art;你必須這樣寫:

HTML:

<div class="left">left fix width</div> 
<div class="right">right no fix width</div> 

CSS:

.left{float:left;width:200px;margin-right:30px} 
.right{overflow:hidden} 

檢查小提琴http://jsfiddle.net/sandeep/4RN2j/

+0

我覺得這是他的正是後。 – thirtydot

+0

謝謝thirtydot;那招我從你那裏學習:)。檢查此問題http://stackoverflow.com/questions/6056759/two-divs-the-same-line-one-dynamic-width-one-fixed/6057049#6057049 – sandeep

+0

如果您嘗試垂直居中,這不起作用你的行元素,但這是另一個線程的問題。 – Pieter