在 webkit 中清除浮动的最简单方法是什么?

发布于 2024-09-07 21:15:33 字数 118 浏览 1 评论 0原文

我正在制作一个 Google Chrome 插件。因此,注入的CSS只需要在webkit中起作用。 webkit 特有的清除浮动的方法是什么?

通过清除浮动,我的意思是让父元素包围其中包含的所有浮动子元素。

I'm making a Google Chrome plugin. Therefore, the injected CSS need only work in webkit. What is the webkit-specific way of clearing floats?

By clearing floats, I mean make a parent element enclose all floating children contained within.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

杀手六號 2024-09-14 21:15:33

如果你不需要关心IE的bug,你可以做一个清晰的样式(让元素不占用空间),就像这样简单:

.Clear { clear: both; height: 0; }

作为对比,考虑IE单字符高度bug的样式 添加清除标记的另

.Clear { clear: both; height: 0; overflow: hidden; }

一种方法是在浮动的父元素上设置溢出样式,这将使其继续其子元素。例如,您可以使用 overflow:hidden 但不指定大小,这样父级将根据其子级调整大小。

If you don't need to care about the IE bugs, you can make a clearing style (for an element not to take up space) as simple as:

.Clear { clear: both; height: 0; }

as comparison, a style that takes the IE one-character-height bug into acount would be:

.Clear { clear: both; height: 0; overflow: hidden; }

An alternative to adding a clearing tag, is to set an overflow style on the parent element of the floats, that will make it contin it's children. You can for example use overflow:hidden but without specifying a size, that way the parent will be sized by it's children.

若有似无的小暗淡 2024-09-14 21:15:33

display: inline-block 成功了。

display: inline-block did the trick.

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