Element with Overflow:auto affected by Floating Element

て烟熏妆下的殇ゞ 提交于 2019-12-23 17:13:41

问题


Can someone explain to me why overflow has the following effect.

In the jsfiddle below I have a Div floated to the left with a width and height set. Next I have a Content div. You could think about this as a left navigation and a content of a site layout.

Inside the content I have two Divs which are identical apart from one has overflow:auto the other doesn't. The one with overflow:auto currently respects the floated div and shortens its width to not clash with it. Were as the other one simply keeps its full width and runs underneth the floated div.

Although the overflow:auto gives a very userful behaviour I do not understand why it cares about the floated item. I thought if a element has a certain width and the content inside that cannot fit, then it will do your requested behaviour but this is sort of applying the behaviour to the element itself

http://jsfiddle.net/9bEDj/1/

Can someone clarify this for me and explain why this is the behaviour or if it shouldn't actually be doing this and its a quirk!


回答1:


Here is a fabulous description on the float/overflow magic
http://colinaarts.com/articles/the-magic-of-overflow-hidden/

It's the intended behaviour that elements with overflow other than visible should respect the floats, so you can use it with not causing any fuzz




回答2:


It happens because setting overflow establishes a new block formatting context, and block formatting contexts do not overlap floats.



来源:https://stackoverflow.com/questions/9807828/element-with-overflowauto-affected-by-floating-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!