How does CSS 'overflow:hidden' work to force an element (containing floated elements) to wrap around floated elements?

前端 未结 3 1168
野趣味
野趣味 2020-11-28 10:29

Anyone know why overflow:hidden forces an element with floated elements to wrap the elements?

I really want to understand the inner workings rather than just using

3条回答
  •  [愿得一人]
    2020-11-28 11:24

    Well, seems there is no 'actual' explanation for why this happens (not one that I can understand anyway - e.g. the CSS spec excerpt provided in one of the responses simply explained that a box with floated content should not expand to wrap the floated elements - which is fine and that is logical and I completely get that)

    I was hoping this wasn't some random hack that forced the parent element to wrap it's floated child elements, but it seems every resource I look at just says to use it and not why it works.

    Must just be a hack.

    The most useful resource I came across (or the one that gave the most detail - albeit not as much details as I needed) was from Quirksmode: http://www.quirksmode.org/css/clearing.html

    Thanks if anyone else can shed light as to whether this is a random browser rendering quirk or has a logical explanation for working the way it does.

    M.

提交回复
热议问题