We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
W3C对BFC的定义如下: 浮动元素和绝对定位元素,非块级盒子的块级容器(例如 inline-blocks, table-cells, 和 table-captions),以及overflow值不为"visiable"的块级盒子,都会为他们的内容创建新的BFC(Block Fromatting Context, 即块级格式上下文);
/** 清除浮动的方法:**/ overflow: hidden; /** 是不是很熟悉?**/
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> body {padding: 0;margin: 0;} .container { background: #08BDEB; } .inner { background: green; height: 100px; margin: 10px 0; } </style> </head> <body> <div class="container"> <div class="inner"></div> <div class="inner"></div> <div class="inner"></div> </div> </body> </html>
如上图:1和2,2和3之间的外边距重叠了,而且合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者;
外边距合并指的是,当两个垂直外边距相遇时,它们将形成一个外边距。 合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者。 解决办法是给中间的div套上一个BFC(渲染规则第3条:每个BFC都是独立的容器,外边的元素不会影响里边的元素)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> body {padding: 0;margin: 0;} .container { background: #08BDEB; } .inner { background: green; height: 100px; margin: 10px 0; } .middle { margin: 20px 0; } </style> </head> <body> <div class="container"> <div class="inner"></div> <div style="overflow: hidden;"> <div class="inner middle"></div> </div> <div class="inner"></div> </div> </body> </html>
参考:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1. 定义
2. 触发条件
3. 渲染规则
4. 应用
如上图:1和2,2和3之间的外边距重叠了,而且合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者;
参考:
The text was updated successfully, but these errors were encountered: