28_浮动2.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. border: 3px solid black;
  10. /* height: 200px; */
  11. }
  12. .item{
  13. width: 200px;
  14. height: 200px;
  15. background-color: red;
  16. float: left;
  17. }
  18. .box2{
  19. height: 300px;
  20. width: 300px;
  21. background-color: blue;
  22. }
  23. /* p{
  24. clear: both;
  25. } */
  26. /* ::after 伪元素 */
  27. /* 在当前元素中最后面添加一个伪元素(假的标签) */
  28. .box::after{
  29. /* content 伪元素的内容 必须要有 伪元素默认为行元素*/
  30. content: "";
  31. /* display 块级元素 */
  32. display: block;
  33. /* clear 清除浮动. 必须作用于块级元素上 */
  34. clear: both;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <div class="box">
  40. <div class="item">1</div>
  41. <div class="item">2</div>
  42. <div class="item">3</div>
  43. <!-- <p></p> -->
  44. </div>
  45. <div class="box2"></div>
  46. </body>
  47. </html>