神秘的人overflow: hidden;是你的朋友。它阻止了与浮动相邻的元素在浮动之后延伸—我想这就是您要寻找的布局。
以下是一些经过稍微编辑的HTML:我认为您#的ids中不能包含字符:
inner div 1. Some text...
inner div 2...
这是实现所需布局的CSS。
(我为带有HTML 条件注释的 IE 6添加了其他CSS 。我只是注意到您实际上也不需要它在IE 6中也可以工作,但是如果您想对IE 6用户好一点的话...)
#outer {
overflow: hidden;/* Makes #outer contain its floated children */
width: 100%;
/* Colours and borders for illustration purposes */
border: solid 3px #666;
background: #ddd;
}
#inner1 {
float: left;/* Make this div as wide as its contents */
/* Colours and borders for illustration purposes */
border: solid 3px #c00;
background: #fdd;
}
#inner2 {
overflow: hidden;/* Make this div take up the rest of the horizontal space, and no more */
/* Colours and borders for illustration purposes */
border: solid 3px #00c;
background: #ddf;
}
经过测试并在IE 6、7和8中工作;Firefox 3.5;和Chrome 4。