26_BFC2.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. /* BFC 区域 */
  9. /* 生成BFC区域后 内不元素不会与外部元素关联 */
  10. .box{
  11. width: 400px;
  12. height: 400px;
  13. background-color: blue;
  14. /* 开启 BFC */
  15. overflow: hidden;
  16. }
  17. /* 内部元素的margin-top 超出父元素范围。(外边距溢出) */
  18. .box2{
  19. width: 200px;
  20. height: 200px;
  21. background-color: red;
  22. margin-top: 100px;
  23. /* margin-left: 100px; */
  24. }
  25. .box3,.box4{
  26. width: 400px;
  27. height: 400px;
  28. }
  29. /* 垂直外边距合并 */
  30. .box3{
  31. background-color: red;
  32. margin-bottom: 50px;
  33. }
  34. .box4{
  35. margin-top: 50px;
  36. background-color: blue;
  37. }
  38. .box5{
  39. overflow: hidden;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <!-- <div class="box">
  45. <div class="box2"></div>
  46. </div> -->
  47. <div class="box5">
  48. <div class="box3"></div>
  49. </div>
  50. <div class="box4"></div>
  51. </body>
  52. </html>