Can overflow:hidden affect layout?

不想你离开。 提交于 2019-12-17 06:50:17

问题


There's no way for me to explain this except to refer to the following example on JS Fiddle- in it, the last BLUE box does not extend to 100% of the width as expected after I introduce an overflow:hidden attribute.

I was under the impression overflow:hidden would affect visibility aspects only, and not interfere with layout. Can someone explain what is going on in this example?

EDIT: This problem seems limited to webkit browsers (e.g. Chrome)


回答1:


It is because overflow: hidden, among other properties, introduces a new block formatting context.

You can read about the effects in this great article: The magic of overflow: hidden

UPDATE: I've rewritten your jsFiddle into something that is working (tested on Chrome). Instead of defining margin-left on the #red and #blue (which would act differently due to overflow: hidden), I've put a margin-right on #yellow.



来源:https://stackoverflow.com/questions/6128139/can-overflowhidden-affect-layout

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