浮动会互相影响吗?
我的页面有 3 列,一列向左浮动,一列向右浮动,一列在中间。 在中央块内,我需要使用多个块,其中图像向左浮动,以使文本位于其左侧。这会导致一个奇怪的显示错误,每个块都会缩进一点。明确:既修复了错误,又打破了页面框架的块。 该页面的 html 代码的简化版本如下:
<div id="leftbar">Navigation</div>
<div id="rightbar">Right bar</div>
<div id="content">
<div class='content-block'>
<span class='image-floated'><img src='image'/></span>
<span>Some content</span>
<div class='someother_content'>content</div>
<div class='content_bottom'>stuff</div>
</div>
<div class='content-block'>
<span class='image-floated'><img src='image'/></span>
<span>Some content</span>
<div class='someother_content'>content</div>
<div class='content_bottom'>stuff</div>
</div>
</div>
css 如下:
#leftbar
{
float: left;
width: 10%;
}
#rightbar
{
float: right;
width: 20%;
}
.image-floated
{
float: left;
width: 55px;
}
.content-block
{
padding-top: 3px;
}
请问我该如何解决这个问题? 先感谢您
I have a page with 3 columns, one floated to the left, one to the right and one in the center.
Within the central block I need to use several blocks with an image floated to the left to have the text to its left. This makes for a strange display bug where each block is indented a bit. A clear: both fixes the bug but also breaks the blocks out of the page frame.
A simplified version of the html code of the page can be found below:
<div id="leftbar">Navigation</div>
<div id="rightbar">Right bar</div>
<div id="content">
<div class='content-block'>
<span class='image-floated'><img src='image'/></span>
<span>Some content</span>
<div class='someother_content'>content</div>
<div class='content_bottom'>stuff</div>
</div>
<div class='content-block'>
<span class='image-floated'><img src='image'/></span>
<span>Some content</span>
<div class='someother_content'>content</div>
<div class='content_bottom'>stuff</div>
</div>
</div>
and the css is as follows:
#leftbar
{
float: left;
width: 10%;
}
#rightbar
{
float: right;
width: 20%;
}
.image-floated
{
float: left;
width: 55px;
}
.content-block
{
padding-top: 3px;
}
How can I fix this please ?
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在
#content
中编写overflow:hidden;
即可:检查小提琴 http://jsfiddle.net/RcEBf/
just write
overflow:hidden;
in your#content
like this:Check the fiddle http://jsfiddle.net/RcEBf/
如果您为左栏指定适当的高度,它将阻止图像浮出中央
div
。If you give your left column an appropriate height, it will stop the image floating out of the central
div
.