如何避免空清除div? [英] How to avoid empty clear divs?

查看:121
本文介绍了如何避免空清除div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在使用很多浮动,像这样:

I have been using a lot of floats recently like this:

<div id="buttons">
  <input type="button" id="btn1" value="Button One">
  <input type="button" id="btn2" value="Button Two">
  <input type="button" id="btn3" value="Button Three">
</div>

有时我会在右边浮动一个按钮。有时候我会把它们全部漂浮在右边。这是问题开始的地方。如果我这样做,它真的抛出流程,所以我必须继续把这些:

Sometimes I'll float a button to the right. Sometimes I'll float all of them to the right. This is where the problem starts. It really throws the flow off if I do that so I have to keep putting in these:

<div style="clear:both;"></div>

有没有很好的解决方案?

Is there a good solution to this?

推荐答案

是,在容器上使用 overflow:hidden ie:

Yes, use overflow: hidden on the container ie:

<style type="text/css">
#buttons { overflow: hidden; }
</style>

这篇关于如何避免空清除div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆