练习7_浮动练习.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. padding: 20px;
  12. margin-bottom: 20px;
  13. }
  14. .box div {
  15. width: 200px;
  16. height: 200px;
  17. text-align: center;
  18. line-height: 200px;
  19. color: white;
  20. font-size: 50px;
  21. }
  22. .box .item {
  23. background-color: red;
  24. float: left;
  25. margin-right: 20px;
  26. }
  27. .box .item2 {
  28. background-color: blue;
  29. float: right;
  30. margin-left: 20px;
  31. }
  32. .box .item3{
  33. background-color: green;
  34. }
  35. .box .item-left{
  36. float: left;
  37. }
  38. .box .item-right{
  39. float: right;
  40. }
  41. .box .item-center{
  42. background-color: yellow;
  43. margin: 0 auto;
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <div class="box">
  49. <div class="item">1</div>
  50. <div class="item">2</div>
  51. <div class="item">3</div>
  52. </div>
  53. <div class="box">
  54. <div class="item2">1</div>
  55. <div class="item2">2</div>
  56. <div class="item2">3</div>
  57. </div>
  58. <div class="box">
  59. <div class="item3 item-left">左</div>
  60. <div class="item3 item-right">右</div>
  61. <div class="item3 item-center">中</div>
  62. </div>
  63. </body>
  64. </html>