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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/css/218201.html

猜你在找的CSS相关文章