居中

image.png
居中 div嵌套div,控制子元素的margin,父div width100%,与html一样
image.png

淘宝两侧会有空白,不会全部占满的,大div占满html的宽度,小div在大div中居中,大div包裹小div

cover包裹
nav导航
t top
t-nav-cover 顶部导航栏包裹的元素,起到顶部导航栏包裹的元素

site 网站

顶部居中

index.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>淘宝</title>
  8. <link rel="stylesheet" href="./css/index.css">
  9. </head>
  10. <body>
  11. <div class="t-nav-cover">
  12. <div class="site-nav"></div>
  13. </div>
  14. </body>
  15. </html>

index.css

  1. body{
  2. margin: 0;
  3. }
  4. .t-nav-cover{
  5. width: 100%;
  6. min-width: 1190px;
  7. height: 35px;
  8. background-color: #f5f5f5;
  9. border-bottom: 1px solid #eee;
  10. }
  11. .t-nav-cover .site-nav{
  12. width: 1190px;
  13. height: 35px;
  14. margin: 0 auto;
  15. background-color: #000;
  16. }

image.png
这是最顶部的导航栏

左侧导航栏,下部导航栏,都是是导航栏,都是为了导航,点击触发,点击跳转

布局分析

image.png

左右,同一高度的div划分布局,需要新的div盒子。因为不同一高度的,文档流上下排列,在一个div里面,上下排列。
为了让其左右排列,用div包裹,让div左右排列,div里面的内容上下排列,不用必须用新的div

父元素不设高度,子元素设置高度,父元素会被撑开,父元素应该包裹子元素,不管写法上,还是视觉效果上

  1. body{
  2. margin: 0;
  3. background-color: #f4f4f4;
  4. }
  5. /* 因为不止最上面的大div要用width100%,min-width,
  6. 每一层都要用到,所以单独抽出个类,就不用每次都写了,而是写上类名,
  7. 用类名代替这些css代码,把css样式封装成一个一个的类,在css上少写,在html上多写类名 */
  8. .layer{
  9. width: 100%;
  10. min-width: 1190px;
  11. }
  12. .t-nav-cover{
  13. /* width: 100%;
  14. min-width: 1190px; */
  15. height: 35px;
  16. background-color: #f5f5f5;
  17. border-bottom: 1px solid #eee;
  18. }
  19. .t-nav-cover .site-nav{
  20. width: 1190px;
  21. height: 35px;
  22. margin: 0 auto;
  23. background-color: #000;
  24. }
  25. .t-main-cover{
  26. /* width: 100%; */
  27. /* height: 121px; */
  28. background-color: #fff;
  29. }
  30. .t-main-cover .main-belt{
  31. width: 1190px;
  32. height: 121px;
  33. margin: 0 auto;
  34. background-color: orange;
  35. }
  36. .main-nav-cover .main-nav{
  37. width: 1190px;
  38. height: 30px;
  39. margin: 0 auto;
  40. background-color: #ff5000;
  41. }
  42. .main-show-area{
  43. width: 1190px;
  44. height: 632px;
  45. margin: 0 auto;
  46. /*可以删掉 */
  47. /* background-color: #666; */
  48. }
  49. .main-show-area .main-show-box{
  50. float: left;
  51. height: 100%;
  52. }
  53. .main-show-area .main-show-box.main-area{
  54. width: 900px;
  55. background-color: pink;
  56. }
  57. .main-show-area .main-show-box.funcs-area{
  58. width: 290px;
  59. background-color: purple;
  60. }
  1. <div class="layer t-nav-cover">
  2. <div class="site-nav"></div>
  3. </div>
  4. <div class="layer t-main-cover">
  5. <div class="main-belt"></div>
  6. </div>
  7. <div class="layer main-nav-cover">
  8. <div class="main-nav"></div>
  9. </div>
  10. <div class="main-show-area">
  11. <div class="main-show-box main-area">
  12. </div>
  13. <div class="main-show-box funcs-area">
  14. </div>
  15. </div>

image.png

  1. body{
  2. margin: 0;
  3. background-color: #f4f4f4;
  4. }
  5. .clearfix::after{
  6. content: "";
  7. display: table;
  8. clear: both;
  9. }
  10. /* 因为不止最上面的大div要用width100%,min-width,
  11. 每一层都要用到,所以单独抽出个类,就不用每次都写了,而是写上类名,
  12. 用类名代替这些css代码,把css样式封装成一个一个的类,在css上少写,在html上多写类名 */
  13. .layer{
  14. width: 100%;
  15. min-width: 1190px;
  16. }
  17. .t-nav-cover{
  18. /* width: 100%;
  19. min-width: 1190px; */
  20. height: 35px;
  21. background-color: #f5f5f5;
  22. border-bottom: 1px solid #eee;
  23. }
  24. .t-nav-cover .site-nav{
  25. width: 1190px;
  26. height: 35px;
  27. margin: 0 auto;
  28. background-color: #000;
  29. }
  30. .t-main-cover{
  31. /* width: 100%; */
  32. /* height: 121px; */
  33. background-color: #fff;
  34. }
  35. .t-main-cover .main-belt{
  36. width: 1190px;
  37. height: 121px;
  38. margin: 0 auto;
  39. background-color: orange;
  40. }
  41. .main-nav-cover .main-nav{
  42. width: 1190px;
  43. height: 30px;
  44. margin: 0 auto;
  45. background-color: #ff5000;
  46. }
  47. .main-show-area{
  48. width: 1190px;
  49. /* height: 632px; */
  50. margin: 0 auto;
  51. /*可以删掉 */
  52. /* background-color: #666; */
  53. }
  54. /* .main-show-area .main-show-box{
  55. float: left;
  56. height: 100%;
  57. }
  58. .main-show-area .main-show-box.main-area{
  59. width: 900px;
  60. background-color: pink;
  61. }
  62. .main-show-area .main-show-box.funcs-area{
  63. width: 290px;
  64. background-color: purple;
  65. } */
  66. /* .main-show-area .main-show-box{
  67. float: left;
  68. height: 100%;
  69. } */
  70. .main-show-area .main-area{
  71. float: left;
  72. width: 900px;
  73. /* height: 100%; */
  74. height: 632px;
  75. /* background-color: pink; */
  76. }
  77. .main-show-area .main-area .main-show{
  78. height: 522px;
  79. /* background-color: pink; */
  80. margin-bottom: 10px;
  81. }
  82. .main-show-area .main-area .main-show .nav-menu-list{
  83. float: left;
  84. width: 190px;
  85. height: 100%;
  86. background-color: blue;
  87. }
  88. .main-show-area .main-area .head-line{
  89. width: 890px;
  90. height: 100px;
  91. margin-right: 10px;
  92. background-color: green;
  93. }
  94. .main-show-area .main-area .main-show .sliders-wrap{
  95. float: left;
  96. width: 520px;
  97. height: 512px;
  98. margin: 10px 0 0 10px;
  99. /* background-color: pink; */
  100. }
  101. .main-show-area .main-area .main-show .sliders-wrap .main-slider{
  102. height: 280px;
  103. background-color: pink;
  104. }
  105. .main-show-area .main-area .main-show .sliders-wrap .goods-silder{
  106. height: 230px;
  107. background-color: #ff5000;
  108. /* overflow: hidden; */
  109. }
  110. .main-show-area .main-area .main-show .sliders-wrap .goods-silder .goods-slider-hd{
  111. height: 18px;
  112. /* margin-top: 10px; */
  113. padding-top: 10PX;
  114. /* background-color: #000; */
  115. }
  116. /* .goods-slider{
  117. height: 230px;
  118. background-color: #000;
  119. } */
  120. .main-show-area .main-area .main-show .hot-sale-imgs{
  121. float:left;
  122. width: 160px;
  123. height: 512px;
  124. margin: 10px 10px 0 ;
  125. /* background-color: red; */
  126. }
  127. .main-show-area .main-area .main-show .hot-sale-imgs .t-img{
  128. height: 280px;
  129. background-color: green;
  130. }
  131. .main-show-area .main-area .main-show .hot-sale-imgs .b-img{
  132. height: 230px;
  133. background-color: yellowgreen;
  134. }
  135. .main-show-area .funcs-area{
  136. float: left;
  137. width: 290px;
  138. height: 632px;
  139. /* background-color: purple; */
  140. margin-top: 10px;
  141. }
  142. .main-show-area .funcs-area .member{
  143. height: 145px;
  144. background-color: blue;
  145. }
  146. .main-show-area .funcs-area .member-tip{
  147. height: 29px;
  148. background-color: green;
  149. }
  150. .main-show-area .funcs-area .member-notice{
  151. height: 108px;
  152. background-color: #ff5000;
  153. }
  154. .main-show-area .funcs-area .member-funcs{
  155. height: 232px;
  156. background-color: #000;
  157. }
  158. .main-show-area .funcs-area .member-apps{
  159. height: 110px;
  160. background-color: pink;
  161. }
  162. .life-belt{
  163. width: 1190px;
  164. height: 166px;
  165. margin: 0 auto;
  166. background-color: #f40;
  167. }
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>淘宝</title>
  8. <link rel="stylesheet" href="./css/index.css">
  9. </head>
  10. <body>
  11. <!-- <div class="t-nav-cover">
  12. <div class="site-nav"></div>
  13. </div>
  14. <div class="t-main-cover">
  15. <div class="main-belt"></div>
  16. </div> -->
  17. <!-- <div class="layer t-nav-cover">
  18. <div class="site-nav"></div>
  19. </div>
  20. <div class="layer t-main-cover">
  21. <div class="main-belt"></div>
  22. </div>
  23. <div class="layer main-nav-cover">
  24. <div class="main-nav"></div>
  25. </div>
  26. <div class="main-show-area clearfix">
  27. <div class="main-show-box main-area">
  28. </div>
  29. <div class="main-show-box funcs-area">
  30. </div>
  31. </div> -->
  32. <!-- 最顶上的区域 有登录按钮 -->
  33. <div class="layer t-nav-cover">
  34. <div class="site-nav"></div>
  35. </div>
  36. <!-- 带搜索框的区域 -->
  37. <div class="layer t-main-cover">
  38. <div class="main-belt"></div>
  39. </div>
  40. <!-- 带主题市场的区域 -->
  41. <div class="layer main-nav-cover">
  42. <div class="main-nav"></div>
  43. </div>
  44. <!-- 主展示区域 -->
  45. <div class="main-show-area clearfix">
  46. <div class="main-area">
  47. <div class="main-show clearfix">
  48. <!-- 竖栏展示框 -->
  49. <div class="nav-menu-list"></div>
  50. <!-- 中间包含轮播图的区域 -->
  51. <div class="sliders-wrap">
  52. <!-- 轮播图 -->
  53. <div class="main-slider"></div>
  54. <!-- <div class="goods-silder"></div> -->
  55. <div class="goods-silder">
  56. <div class="goods-slider-hd"></div>
  57. </div>
  58. </div>
  59. <div class="hot-sale-imgs">
  60. <div class="t-img"></div>
  61. <div class="b-img"></div>
  62. </div>
  63. </div>
  64. <div class="head-line"></div>
  65. </div>
  66. <div class="funcs-area">
  67. <div class="member"></div>
  68. <div class="member-tip"></div>
  69. <div class="member-notice"></div>
  70. <div class="member-funcs"></div>
  71. <div class="member-apps"></div>
  72. </div>
  73. </div>
  74. <div class="life-belt">
  75. </div>
  76. </body>
  77. </html>

image.png

总结

命名规则

cover 覆盖 是