练习7_浮动.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. .box1 div{
  9. width: 100px;
  10. height: 100px;
  11. background-color: blue;
  12. color: white;
  13. font-size: 30px;
  14. font-weight: bolder;
  15. margin:10px;
  16. text-align: center;
  17. /* line-height 值控制行元素的行高 行元素默认在他所在这一行中垂直居中 */
  18. line-height: 100px;
  19. float: left;
  20. }
  21. .box2 .div2{
  22. width: 100px;
  23. height: 100px;
  24. background-color: red;
  25. margin: 10px;
  26. color: white;
  27. font-size: 30px;
  28. font-weight: bolder;
  29. text-align: center;
  30. line-height: 100px;
  31. float: right;
  32. }
  33. .box3 .div3{
  34. width: 100px;
  35. height: 100px;
  36. background-color: green;
  37. margin: 10px;
  38. color: white;
  39. font-size: 30px;
  40. font-weight: bolder;
  41. text-align: center;
  42. line-height: 100px;
  43. }
  44. .box1,.box2,.box3{
  45. border: 3px solid black;
  46. height: 150px;
  47. }
  48. .box3 .left{
  49. float: left;
  50. /* background-color: rgba(0,255,0,0.2); */
  51. /* margin-top: 100px; */
  52. }
  53. .box3 .center{
  54. color: black;
  55. /* margin-left: 100px; */
  56. margin:10px auto;
  57. }
  58. .right{
  59. float: right;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <!-- 浮动元素会脱离文档流 释放之前占用的位置 会覆盖其他元素 -->
  65. <div class="box1">
  66. <div class="div1">
  67. <span>1</span>
  68. </div>
  69. <div class="div1">2</div>
  70. <div class="div1">3</div>
  71. </div>
  72. <div class="box2">
  73. <div class="div2">1</div>
  74. <div class="div2">2</div>
  75. <div class="div2">3</div>
  76. </div>
  77. <div class="box3">
  78. <div class="div3 left">左</div>
  79. <!-- <div class="div3 center">中</div> -->
  80. <div class="div3 right">右</div>
  81. <div class="div3 center"> 中 </div>
  82. </div>
  83. </body>
  84. </html>