【发布时间】:2014-08-28 06:19:56
【问题描述】:
想象一个具有如下基本结构的页面。主要问题是如何让 .left 背景一直延伸到窗口的左侧,而 .right 延伸到右侧?两者都需要保持固定宽度。
HTML:
<body>
<div class="container">
<header>blah</header>
<article>doodle doo</article>
<div class="left">Left stuff with blue background</div>
<div class="right">Right stuff with red background</div>
<div class="clear"></div>
</div>
<footer>deedle dee</footer>
</body>
CSS:
.container{
width:400px;
margin:0 auto;
}
header{
background-color:grey;
}
.left{
width:200px;
float:left;
background-color:blue;
}
.right{
width:200px;
float:right;
background-color:red;
}
.clear{
clear:both;
}
footer{
background-color:#DDD;
text-align:center;
}
基本思想与this page 相同,但您可能会注意到页面向右滚动了很长一段路 - 截断实际上不起作用。
【问题讨论】:
-
在这种情况下,它们应该保持相同的高度。