14_浮动.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: 200px; */
  11. border: 3px solid black
  12. }
  13. /* float 浮动元素 会让元素横向依次排列 */
  14. .box div {
  15. width: 100px;
  16. height: 100px;
  17. background-color: blue;
  18. margin-left: 10px;
  19. float: right;
  20. color: white;
  21. font-size: 30px;
  22. font-weight: bolder;
  23. text-align: center;
  24. line-height: 100px;
  25. }
  26. p {
  27. /* clear 清除浮动元素 */
  28. clear: both;
  29. }
  30. /* span {
  31. clear: both;
  32. } */
  33. </style>
  34. </head>
  35. <body>
  36. <div class="box">
  37. <div class="div1">1</div>
  38. <div class="div2">2</div>
  39. <div class="div3">3</div>
  40. <div class="div4">4</div>
  41. <p></p>
  42. <!-- <span>hello</span> -->
  43. </div>
  44. </body>
  45. </html>