8.浮动.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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,.two,.three {
  9. width: 200px;
  10. height: 200px;
  11. /* display: inline-block; */
  12. }
  13. .one {
  14. float: left;
  15. background: #00f;
  16. }
  17. .two {
  18. width: 300px;
  19. float: left;
  20. background: #f00;
  21. }
  22. .three {
  23. float: left;
  24. background: #ff0;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <!--
  30. 页面的组成:
  31. 文档流 标准流
  32. 浮动
  33. 为什么要使用浮动?
  34. 因为要让内容在一行展示
  35. float:left/right/none
  36. 浮动会导致元素脱离文档流 不占位
  37. 浮动 对浮动前的元素无影响 只对浮动后的元素有影响
  38. 缺点:会导致父元素盒子高度塌陷
  39. -->
  40. <div class="main">
  41. <div class="one"></div>
  42. <div class="two"></div>
  43. <div class="three"></div>
  44. </div>
  45. </body>
  46. </html>