【发布时间】:2013-05-14 22:18:04
【问题描述】:
我正在尝试设计一个页面,左侧有一个浮动图像,右侧有一个 div,其文本和块元素在图像周围流动,然后在图像下方有更多 div。使用此代码查看http://jsfiddle.net/BcjzK/3/:
.container {
width:700px;
border:solid 1px gray;
}
.content {
width:460px;
border:solid 1px red;
margin-right:0px;
margin-left:auto;
}
.extra-content {
width:230px;
border:solid 1px green;
}
img {
float:left;
border:solid 1px blue;
}
blockquote {
border:solid 1px gray;
width:30%;
float:right;
}
和
<div class="container">
<img src="http://hazelden.ca/sample.png" width="320" height="auto" />
<div class="content">
<p> Some content, some blockquotes and images</p>
</div>
<div class="extra-content">
Some more text
</div>
</div>
大图将被设置为特定宽度,其高度设置为“自动”。
我无法让绿色边框的 div (class="extra-content") 紧贴在大图像正下方的空间中,而红色边框的 div (class="内容”)正常流动。我尝试了 clear: 在各种元素中的多种组合并重新排序 div。
我希望这是我没有看到的简单的东西。
【问题讨论】:
-
您是否尝试过将 img 和 content 都设置为 float:left;所以他们只是流动,然后添加额外的内容,所以它应该就在下面?但请确保您还添加了 clear:right;关于内容
-
因为图像和内容 div 的组合宽度比容器 div 宽,浮动内容 div 只会强制它位于图像下方。没有组合 float: 和 clear: 似乎有效。