我想创建一个简单的标题+内容+页脚+侧栏。侧边栏必须悬浮在页眉和内容元素上方,并且如果内容比内容高,则必须将页脚向下推(如下所示:http://jsfiddle.net/gWLFN/7/)。浮动右元素推下IE7中的下一个元素
的HTML:
<div id="wrapper">
<div id="sidebar">sidebar</div>
<div id="header">header</div>
<div id="content">content</div>
<div style="clear:both"></div>
<div id="footer">footer</div>
</div>
的CSS:
#wrapper { width:500px }
#header { width:500px; height:100px; background-color:red }
#content { width:500px; height:300px; background-color:green }
#footer { width:500px; height:100px; background-color:blue }
#sidebar {
float:right;
margin-top:50px;
width:100px;
height:500px;
background-color: yellow;
border:1px solid white;
}
的问题是,在IE7中,边栏下推其他元素。我认为这是因为标题+侧栏的总宽度大于包装宽度。我在IE7中发现了很多关于float:right的问题,但是它们都是宽度不超过wrapper的。
我选择了float:right而不是绝对定位,因为footer的位置必须依赖侧边栏高度(如果有人知道如何用绝对定位完成这个操作,那么完美!)。
我希望有任何想法来解决这个问题。
完美!我曾试过没有宽度,但与该元素命令它没有工作。随着你的改变,一切都在原地。 – mariogl 2012-02-23 11:24:31