8.浮动.html 1.3 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. #box {
  9. width: 800px;
  10. height: 800px;
  11. margin: 0 auto;
  12. border: 3px solid #000;
  13. }
  14. #part1 {
  15. width: 200px;
  16. height: 200px;
  17. /* display: inline-block; */
  18. float: left;
  19. background-color: #f00;
  20. }
  21. #part2 {
  22. width: 230px;
  23. height: 230px;
  24. /* margin-top: 10px; */
  25. /* display: inline-block; */
  26. float: left;
  27. background-color: #ff0;
  28. }
  29. #part3 {
  30. width: 200px;
  31. height: 200px;
  32. /* float: left; */
  33. background-color: #00f;
  34. }
  35. /*
  36. 当想让元素在一行展示时
  37. 使用浮动
  38. float:left/right/none
  39. 使元素脱离文档流 不占位
  40. 排版:
  41. 文档排版
  42. 浮动
  43. */
  44. </style>
  45. </head>
  46. <body>
  47. <div id="box">
  48. <div id="part1"></div>
  49. <div id="part2"></div>
  50. <div id="part3"></div>
  51. </div>
  52. </body>
  53. </html>