2009-08-05 59 views
0

我有2格在頁面如何使100%的寬度爲2格

<div id="main"></div> 
<div id="panel"></div> 

和使用浮動,使在左主幹,和麪板的右側

#photos-main { 
float: left; 
width: 800px; 
position: relative; 
} 

#panel { 
float: left; 
margin-left: 830px; 
position: absolute; 
} 

我不想讓面板填充左頁空間,我應該使用哪個CSS?

回答

3

只是不漂浮它,並使其相對定位。取出保證金。浮動「主」意味着它將一直位於「面板」的左側。如果您定義「主要」您想要的方式,「面板」將自動佔用剩餘的空間。

#photos-main { 
float: left; 
width: 800px; 
position: relative; 
} 

#panel { 
} 
0

你可以用這種方法浮動做到這一點:

#photos-main { 
float: left; 
width: 800px; 
} 

#panel { 
float: right; /*to have the panel on the right side*/ 
width: 100px; /*with a width of 100px*/ 
} 

然後你必須包裝在兩個標籤與另一個,這讓這兩個元素的總寬度。

要澄清這兩列的佈局,並把例如一個腳註在下面,把另一個放在你的HTML-Structure中,並設置成簡單的css「clear:both;」,這樣浮動就會停止。

完全樣本

HTML

<div id="wrap"> 
    <div id="photos-main"></div> 
    <div id="panel"></div> 
    <div id="clear"></div> 
</div> 

CSS

#wrap { 
width: 900px; 
} 

#photos-main { 
float: left; 
width: 800px; 
} 

#panel { 
float: right; /*to have the panel on the right side*/ 
width: 100px; /*with a width of 100px*/ 
} 

#clear { 
clear:both; 
}