| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box1{
- width: 400px;
- height: 400px;
- background-color: red;
- /* 开启BFC */
- overflow: hidden;
- }
- .box2{
- width: 200px;
- height: 200px;
- background-color: blue;
- margin-top: 50px;
-
- }
- .box3{
- width: 200px;
- height: 200px;
- background-color: green;
- margin-bottom: 100px;
- }
- .box4{
- width: 200px;
- height: 200px;
- background-color: yellow;
- margin-top: 30px;
- }
- .box5{
- overflow: hidden;
- }
- </style>
- </head>
- <body>
- <!-- 外边距溢出 -->
- <!-- BFC 隔绝内部与外界元素 让他们相互之间不会有接触 -->
- <!-- BFC 会创建一个独立的上下文环境 让内部元素不会影响到外部元素 -->
- <!-- overflow: hidden; 会触发BFC -->
- <!-- <div class="box1">
- <div class="box2"></div>
- </div> -->
- <!--外边距合并 上下两个外边距会合并为一个 以最大的为准 -->
- <div class="box5">
- <div class="box3"></div>
- </div>
- <div class="box4"></div>
- </body>
- </html>
|