浮动.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. .one {
  9. width: 200px;
  10. height: 200px;
  11. border: 1px solid #f00;
  12. /* background: #00f; */
  13. float: left;
  14. }
  15. .two {
  16. width: 200px;
  17. height: 200px;
  18. border: 1px solid #f00;
  19. /* background: #f0f; */
  20. float: left;
  21. }
  22. .three {
  23. width: 200px;
  24. height: 200px;
  25. border: 1px solid #f00;
  26. /* background: #0ff; */
  27. float: left;
  28. }
  29. .four {
  30. width: 200px;
  31. height: 200px;
  32. border: 1px solid #f00;
  33. /* background: #ff0; */
  34. /* float: left; */
  35. }
  36. /*
  37. 浮动
  38. 为什么使用浮动:因为想让元素在一行显示
  39. float:left/right
  40. 添加浮动属性后对浮动前的元素无影响,对浮动后的元素有影响
  41. 浮动会导致元素脱离文档流 不占位
  42. 缺点:会导致父元素的高度塌陷
  43. */
  44. </style>
  45. </head>
  46. <body>
  47. <div class="main">
  48. <div class="one">1</div>
  49. <div class="two">2</div>
  50. <div class="three">3</div>
  51. </div>
  52. </body>
  53. </html>