2009-08-05 77 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; 
}