微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CSS’overflow:hidden’如何强制元素(包含浮动元素)来包围浮动元素?

任何人都知道为什么overflow:hidden强制一个包含浮动元素的元素来包装元素?

我真的想了解内在的工作,而不仅仅是使用它,并相信“它只是工作”。

当包含的元素与浮动的子元素以相同的方向浮动时,我可以理解它是如何工作的,但是overflow:hidden意味着裁剪溢出的内容(当与position:absolute / relative一起使用时)。

任何信息赞赏。

解决方法

Floats,absolutely positioned
elements,inline-blocks,table-cells,
table-captions,and elements with
‘overflow’ other than ‘visible’
(except when that value has been
propagated to the viewport) establish
new block formatting contexts.

In a block formatting context,each
Box’s left outer edge touches the left
edge of the containing block (for
right-to-left formatting,right edges
touch). This is true even in the
presence of floats (although a Box’s
line Boxes may shrink due to the
floats),unless the Box establishes a
new block formatting context (in which
case the Box itself may become
narrower due to the floats).

块格式上下文清除浮点数。资料来源:http://www.w3.org/TR/CSS2/visuren.html#block-formatting

原文地址:https://www.jb51.cc/css/218201.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。