6.浮动.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * {
  9. margin: 0;
  10. padding: 0;
  11. list-style: none;
  12. text-decoration: none;
  13. box-sizing: border-box;
  14. }
  15. .box {
  16. /* width: 1500px; */
  17. }
  18. .header {
  19. width: 100%;
  20. height: 75px;
  21. /* background: #00f; */
  22. }
  23. .header .nav {
  24. width: 1200px;
  25. height: 100%;
  26. /* background: #ff0; */
  27. /* 已知宽高的盒子水平居中
  28. auto 自适应
  29. */
  30. margin: 0 auto;
  31. }
  32. .header .nav ul {
  33. overflow: hidden;
  34. }
  35. .header .nav ul li {
  36. float: left;
  37. margin-left: 25px;
  38. margin-top: 22px;
  39. }
  40. .header .nav ul li a {
  41. color: #000;
  42. }
  43. .header .nav ul li:first-child {
  44. margin-left: 0;
  45. }
  46. .header .nav ul li:first-child a {
  47. color: #31ccff;
  48. }
  49. .header .nav ul li a:hover {
  50. color: #31ccff;
  51. }
  52. .main div {
  53. width: 200px;
  54. height: 200px;
  55. /* float: left; */
  56. }
  57. .main .one {
  58. background: #f00;
  59. }
  60. .main .two {
  61. background: #0ff;
  62. float: left;
  63. }
  64. .main .three {
  65. width: 400px;
  66. height: 400px;
  67. float: left;
  68. background: #f0f;
  69. }
  70. .main .four {
  71. height: 300px;
  72. background: #0f0;
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <!--
  78. 为什么要语义化?
  79. 1.高效、便携开发
  80. 2.搜索引擎寻找信息
  81. 想让标签在一行展示?
  82. 浮动:让元素在一行展示
  83. float:left/right/none
  84. 特点:脱离文档流 不占位
  85. -->
  86. <div class="box">
  87. <!-- 头部样式 -->
  88. <div class="header">
  89. <div class="nav">
  90. <ul>
  91. <li><a href="">内容1</a></li>
  92. <li><a href="">内容2</a></li>
  93. <li><a href="">内容3</a></li>
  94. <li><a href="">内容4</a></li>
  95. <li><a href="">内容5</a></li>
  96. </ul>
  97. </div>
  98. </div>
  99. <!-- 主体样式 -->
  100. <div class="main">
  101. <div class="one"></div>
  102. <div class="two"></div>
  103. <div class="three"></div>
  104. <div class="four"></div>
  105. </div>
  106. <!-- 尾部样式 -->
  107. <div class="footer"></div>
  108. </div>
  109. </body>
  110. </html>