Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2、overflow:hidden清楚浮动的原理 #2

Open
shengq666 opened this issue Jun 23, 2020 · 1 comment
Open

2、overflow:hidden清楚浮动的原理 #2

shengq666 opened this issue Jun 23, 2020 · 1 comment

Comments

@shengq666
Copy link
Owner

No description provided.

@shengq666
Copy link
Owner Author

今天突然想到BFC,就想到了 overflow:hidden 可以触发BFC。就有点疑惑为啥该操作可以清楚浮动,它的本意不是用来超出隐藏的吗?

网上搜了一番在知乎上看到 貘吃馍香 的回答,颇获收益,答案如下:

overflow:hidden 的意思是超出的部分要裁切隐藏掉
那么如果 float 的元素不占普通流位置
普通流的包含块要根据内容高度裁切隐藏
如果高度是默认值auto
那么不计算其内浮动元素高度就裁切,就有可能会裁掉float
这是反布局常识的

所以如果没有明确设定容器高情况下
它要计算内容全部高度才能确定在什么位置hidden
浮动的高度就要被计算进去
顺带达成了清理浮动的目标
同理
overflow 非默认值
position 非默认值
float 非默认值等 都是遵循这个布局计算思路

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant