3.浮动.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. .main {
  9. border: 2px solid #000;
  10. }
  11. .one {
  12. background: #f00;
  13. float: left;
  14. width: 200px;
  15. height: 200px;
  16. font-size: 30px;
  17. color: #fff;
  18. }
  19. .two {
  20. background: #0f0;
  21. float: left;
  22. width: 200px;
  23. height: 200px;
  24. font-size: 30px;
  25. color: #fff;
  26. }
  27. .three {
  28. background: #00f;
  29. float: left;
  30. width: 200px;
  31. height: 200px;
  32. font-size: 30px;
  33. color: #fff;
  34. }
  35. img {
  36. float: left;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <!-- <img src="../day1/images/img01.gif" alt="">
  42. <img src="../day1/images/img01.gif" alt="">
  43. <img src="../day1/images/img01.gif" alt=""> -->
  44. <!--
  45. 为什么使用浮动:想让元素在一行显示
  46. float:left/right;
  47. 问题:浮动会导致父元素高度塌陷
  48. 因为浮动会让元素脱离文档流 不占位
  49. -->
  50. <div class="main">
  51. <div class="one">1</div>
  52. <div class="two">2</div>
  53. <div class="three">3</div>
  54. 我是一段话
  55. </div>
  56. </body>
  57. </html>