浮动会互相影响吗?

发布于 2024-12-13 15:47:03 字数 1182 浏览 1 评论 0原文

我的页面有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满身野味 2024-12-20 15:47:03

只需在 #content 中编写 overflow:hidden; 即可:

#content{overflow:hidden;}

检查小提琴 http://jsfiddle.net/RcEBf/

just write overflow:hidden; in your #content like this:

#content{overflow:hidden;}

Check the fiddle http://jsfiddle.net/RcEBf/

如果没结果 2024-12-20 15:47:03

如果您为左栏指定适当的高度,它将阻止图像浮出中央 div

#leftbar
{
float: left;
width:  10%;
height: 500px;
}

If you give your left column an appropriate height, it will stop the image floating out of the central div.

#leftbar
{
float: left;
width:  10%;
height: 500px;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文