2013-05-16 77 views
0

我在父div中設置兩個div - 左側的邊欄&右側的內容區域。我需要將我的內容區域(具有固定寬度)的位置設置爲始終在邊欄右側15px(即使瀏覽器窗口/邊欄延伸)。設置相對於另一個百分比寬度div的位置的div的位置

設置側邊欄的位置:絕對& a%寬度對側欄本身完美工作,但由於側欄位置是絕對的,因此內容無法識別側欄的位置&無法相對於其定位與CSS。

這裏是什麼,我想實現的圖像:

enter image description here

回答

2

你爲什麼要使用絕對的邊欄位置?

我只想做這樣

<div class="container"> 
     <div class="sidebar"> 
      <p>This is your sidebar</p> 
     </div> 
     <div class="content"> 
      <p>This is your content</p> 
     </div> 
    </div> 


.container {width:100%; height: 1000px; background:blue;} /*didn't supply a width*/ 
.sidebar {width:25%; float:left; min-height:200px; background:lightblue; margin-right:15px;} /*you said sidebar has a % width*/ 
.content {width:250px; height:200px; background:red; float:left;} /*you said content had fixed width*/ 

Link to JS Fiddle to have a look

除非我不理解你的問題?

+0

我需要在側邊欄和內容之間的中間邊緣。在你的小提琴中,內容寬度是從容器中設置的(不管側邊欄是否存在)。側邊欄實際上與內容重疊。 – SeekingCharlie

+0

感謝編輯,@詹姆斯。 – SeekingCharlie

+0

對不起,最初的內容div沒有浮動內容。很高興有幫助。 – James

相關問題