27_浮动.html 887 B

12345678910111213141516171819202122232425262728293031
  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: 200px;
  10. height: 200px;
  11. background-color: red;
  12. color: white;
  13. font-size: 30px;
  14. text-align: center;
  15. line-height: 200px;
  16. /* display: inline-block; */
  17. /* float 表示浮动 可以将块元素横向排列 两个值:left向左 right向右 none不浮动 */
  18. float: right;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <!-- 浮动元素会脱离文档流 -->
  24. <!-- 文档流:正常的文档排列顺序 -->
  25. <!-- 脱离文档流会导致父元素高度塌陷 -->
  26. <div class="box">1</div>
  27. <div class="box">2</div>
  28. <div class="box">3</div>
  29. </body>
  30. </html>