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

[css] 第94天 为什么会出现浮动?在什么时候需要清除浮动呢? #955

Open
haizhilin2013 opened this issue Jul 18, 2019 · 8 comments
Labels
css css

Comments

@haizhilin2013
Copy link
Collaborator

第94天 为什么会出现浮动?在什么时候需要清除浮动呢?

@haizhilin2013 haizhilin2013 added the css css label Jul 18, 2019
@NicholasBaiYa
Copy link

使用了浮动的时候会出现浮动。
子元素浮动脱离文档流,父容器高度塌陷。

@haizhilin2013
Copy link
Collaborator Author

haizhilin2013 commented Jul 19, 2019

@xiangshuo1992 是的,有相关联,第75天的题是问了它的工作原理,今天是问它为什么会出现浮动,还是有些区别。呵呵,我出题时,就猜到你会记得之前有出过了……果然

@xiangshuo1992
Copy link
Contributor

@xiangshuo1992 是的,有相关联,第75天的题是问了它的工作原理,今天是问它为什么会出现浮动,还是有些区别。呵呵,我出题时,就猜到你会记得之前有出过了……果然

我不是说出过了,我其实是把这些问题串起来,让大家联合比较起来看,这样一次性对一个知识点掌握的更丰富。

@haizhilin2013
Copy link
Collaborator Author

@xiangshuo1992 是的,有相关联,第75天的题是问了它的工作原理,今天是问它为什么会出现浮动,还是有些区别。呵呵,我出题时,就猜到你会记得之前有出过了……果然

我不是说出过了,我其实是把这些问题串起来,让大家联合比较起来看,这样一次性对一个知识点掌握的更丰富。

有道理

@nowherebutup
Copy link

1.为了实现文字环绕图片效果
2.父容器的高度塌陷时候,需要清除浮动

@Konata9
Copy link

Konata9 commented Aug 20, 2019

因为在 div + css 代替 table 布局之后,利用 float 很容易进行一些自适应的布局,比如双飞燕和圣杯布局。当然,float 原本的用途就是用来进行文字环绕图片的,当有此需求时,应该使用 float

但是使用 float 之后,由于内部的元素脱离了文档流导致外层包裹元素高度塌陷。此时就需要清除 float 造成的影响。一般使用 clear:both 或者外层触发 BFC。

@MrZ2019
Copy link

MrZ2019 commented Jul 1, 2021

1.为了实现文字环绕图片效果
2.父容器的高度塌陷时候,需要清除浮动

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

No branches or pull requests

6 participants