2011-11-16 39 views
0

我有一個左側div寬度爲200px的固定寬度,然後我希望內容區域佔用剩下的空間。我該如何解決這個問題?我已經做到了這一點...但它不起作用。如何使用左側的寬度

#sidebar { 
     float:left; 
     width:200px; 
     height:100%; 
     background-color: blue; 
    } 

#mainContent { 
    float:left; 
    width: // USE WHATEVER SPACE IS LEFT; 
    height:100%; 
    background-color: red; 
} 
+0

可能重複,需要的第一個自動調整大小根據父div和第二浮動div](http://stackoverflow.com/questions/5645746/2-floating-divs-need-the-first-one-to-auto-size-according-to-parent-div-和第2) – Ryan

回答

3

看一看這段代碼:

http://jsfiddle.net/Ffx8R/

CSS:

#sidebar { 
    float:left; 
    width:200px; 
    height:100%;  
} 

#mainContent { 

    padding-left:200px; 
    height:100%; 

    border:1px blue solid; 
} 
#container 
{ 


    height:200px; 
    clear:both; 
} 

HTML:

<div id="container"> 
    <div id="sidebar">here is sidebar info</div> 
    <div id="mainContent">main Content info</div> 
</div> 
[2周浮動的div
相關問題