Background and CSS Floats

情到浓时终转凉″ 提交于 2019-12-06 08:16:50

You can have the frame float as in:

.frame { width: 960px; margin-left: auto; margin-right: auto;float:left}

and this does it. Or you can put an extra element in the frame with a "clear fix". The pre-made 960 grid does this for you with a class "clear":

(css  .clearfix { clear: both } )
<div class="frame"
   ...
<div class="clearfix" /></div>

Just add this extra rule to your selector:

div.frame {
     overflow:hidden;
}

You shouldn't need to rely on the clearfix unless you have elements coming outside of the frame, nor should you need to rely on any extraneous markup with clear:both.

You need to apply the clearfix class to #bkg.

<div class="frame clearfix" id="bkg">

What you want to do is "clear the float." There are many options out there, some easy, and some quite complex.

The easiest, is to add a clearing div after the last column, like this:

<div class="frame" id="bkg">
  <div class="column">Column A</div>
  <div class="column">Column B<div><br/><br/><br/><br/></div></div>
  <div class="column">Column C</div>
  <div style="clear: both;"></div>
</div>

And that should work.

Here are some other ways (some, pure css):

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!