博客列表 >【CSS】移动端布局-实战淘宝首页

【CSS】移动端布局-实战淘宝首页

可乐随笔
可乐随笔原创
2022年11月27日 20:21:18384浏览

移动端布局-实战淘宝首页

HTML DOM 结构

  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="font_icon/iconfont.css" />
  9. <link rel="stylesheet" href="css/reset.css" />
  10. <link rel="stylesheet" href="css/public.css">
  11. <link rel="stylesheet" href="css/main.css">
  12. </head>
  13. <body>
  14. <!-- 1. 页眉 -->
  15. <header>
  16. <a class="logo" href="https://m.taobao.com"><img src="images/taobao.png" alt="" /></a>
  17. <a class="search" href="">
  18. <span>寻找宝贝店铺</span>
  19. <span>搜索</span>
  20. </a>
  21. <a href="" class="iconfont icon-qiandao-xuanzhong"></a>
  22. </header>
  23. <!-- 2. 主体 -->
  24. <main>
  25. <!-- 1. 顶部导航 -->
  26. <ul class="navs">
  27. <li class="item">
  28. <a href=""><img src="images/navs/tmxb.webp" alt=""></a>
  29. <a href="">天猫新品</a>
  30. </li>
  31. <li class="item">
  32. <a href=""><img src="images/navs/jrbk.webp" alt=""></a>
  33. <a href="">今日爆款</a>
  34. </li>
  35. <li class="item">
  36. <a href=""><img src="images/navs/tmgj.webp" alt=""></a>
  37. <a href="">天猫国际</a>
  38. </li>
  39. <li class="item">
  40. <a href=""><img src="images/navs/fzlx.webp" alt=""></a>
  41. <a href="">飞猪旅行</a>
  42. </li>
  43. <li class="item">
  44. <a href=""><img src="images/navs/tmcx.webp" alt=""></a>
  45. <a href="">天猫超时</a>
  46. </li>
  47. <li class="item">
  48. <a href=""><img src="images/navs/tbch.webp" alt=""></a>
  49. <a href="">淘宝吃货</a>
  50. </li>
  51. <li class="item">
  52. <a href=""><img src="images/navs/sqk.webp" alt=""></a>
  53. <a href="">省钱卡</a>
  54. </li>
  55. <li class="item">
  56. <a href=""><img src="images/navs/ltjb.webp" alt=""></a>
  57. <a href="">领淘金币</a>
  58. </li>
  59. <li class="item">
  60. <a href=""><img src="images/navs/alpm.webp" alt=""></a>
  61. <a href="">阿里拍卖</a>
  62. </li>
  63. <li class="item">
  64. <a href=""><img src="images/navs/fl.webp" alt=""></a>
  65. <a href="">分类</a>
  66. </li>
  67. </ul>
  68. <!-- 2. 快速列表 -->
  69. <ul class="entry">
  70. <li class="item">
  71. <div class="title">
  72. <h3>聚划算</h3>
  73. <span>品牌折扣</span>
  74. </div>
  75. <a href=""><img src="images/items/item-1.webp" alt=""></a>
  76. <a href=""><img src="images/items/item-2.webp" alt=""></a>
  77. </li>
  78. <li class="item">
  79. <div class="title">
  80. <h3>天天特卖</h3>
  81. <span>1元秒杀</span>
  82. </div>
  83. <a href=""><img src="images/items/item-3.webp" alt=""></a>
  84. <a href=""><img src="images/items/item-4.webp" alt=""></a>
  85. </li>
  86. <li class="item">
  87. <div class="title">
  88. <h3>有好货</h3>
  89. <span>好口碑</span>
  90. </div>
  91. <a href=""><img src="images/items/item-5.webp" alt=""></a>
  92. <a href=""><img src="images/items/item-6.webp" alt=""></a>
  93. </li>
  94. <li class="item">
  95. <div class="title">
  96. <h3>每日好店</h3>
  97. <span>头条</span>
  98. </div>
  99. <a href=""><img src="images/items/item-7.webp" alt=""></a>
  100. <a href=""><img src="images/items/item-8.webp" alt=""></a>
  101. </li>
  102. </ul>
  103. <!-- 3. 商品列表 -->
  104. <ul class="list">
  105. <li class="item">
  106. <!-- 图片 -->
  107. <a href=""><img src="images/items/item-9.webp" alt=""></a>
  108. <!-- 描述 -->
  109. <div class="desc">
  110. <a href="">商品简介商品简介商品简介</a>
  111. <div class="price">
  112. <span class="iconfont icon-renminbi_o">14.9</span>
  113. <span>123人购买</span>
  114. </div>
  115. </div>
  116. </li>
  117. <li class="item">
  118. <!-- 图片 -->
  119. <a href=""><img src="images/items/item-10.webp" alt=""></a>
  120. <!-- 描述 -->
  121. <div class="desc">
  122. <a href="">商品简介商品简介商品简介</a>
  123. <div class="price">
  124. <span class="iconfont icon-renminbi_o">14.9</span>
  125. <span>123人购买</span>
  126. </div>
  127. </div>
  128. </li>
  129. <li class="item">
  130. <!-- 图片 -->
  131. <a href=""><img src="images/items/item-11.webp" alt=""></a>
  132. <!-- 描述 -->
  133. <div class="desc">
  134. <a href="">商品简介商品简介商品简介</a>
  135. <div class="price">
  136. <span class="iconfont icon-renminbi_o">14.9</span>
  137. <span>123人购买</span>
  138. </div>
  139. </div>
  140. </li>
  141. <li class="item">
  142. <!-- 图片 -->
  143. <a href=""><img src="images/items/item-12.webp" alt=""></a>
  144. <!-- 描述 -->
  145. <div class="desc">
  146. <a href="">商品简介商品简介商品简介</a>
  147. <div class="price">
  148. <span class="iconfont icon-renminbi_o">14.9</span>
  149. <span>123人购买</span>
  150. </div>
  151. </div>
  152. </li>
  153. <li class="item">
  154. <!-- 图片 -->
  155. <a href=""><img src="images/items/item-13.webp" alt=""></a>
  156. <!-- 描述 -->
  157. <div class="desc">
  158. <a href="">商品简介商品简介商品简介</a>
  159. <div class="price">
  160. <span class="iconfont icon-renminbi_o">14.9</span>
  161. <span>123人购买</span>
  162. </div>
  163. </div>
  164. </li>
  165. <li class="item">
  166. <!-- 图片 -->
  167. <a href=""><img src="images/items/item-14.webp" alt=""></a>
  168. <!-- 描述 -->
  169. <div class="desc">
  170. <a href="">商品简介商品简介商品简介</a>
  171. <div class="price">
  172. <span class="iconfont icon-renminbi_o">14.9</span>
  173. <span>123人购买</span>
  174. </div>
  175. </div>
  176. </li>
  177. <li class="item">
  178. <!-- 图片 -->
  179. <a href=""><img src="images/items/item-15.webp" alt=""></a>
  180. <!-- 描述 -->
  181. <div class="desc">
  182. <a href="">商品简介商品简介商品简介</a>
  183. <div class="price">
  184. <span class="iconfont icon-renminbi_o">14.9</span>
  185. <span>123人购买</span>
  186. </div>
  187. </div>
  188. </li>
  189. <li class="item">
  190. <!-- 图片 -->
  191. <a href=""><img src="images/items/item-16.webp" alt=""></a>
  192. <!-- 描述 -->
  193. <div class="desc">
  194. <a href="">商品简介商品简介商品简介</a>
  195. <div class="price">
  196. <span class="iconfont icon-renminbi_o">14.9</span>
  197. <span>123人购买</span>
  198. </div>
  199. </div>
  200. </li>
  201. <li class="item">
  202. <!-- 图片 -->
  203. <a href=""><img src="images/items/item-17.webp" alt=""></a>
  204. <!-- 描述 -->
  205. <div class="desc">
  206. <a href="">商品简介商品简介商品简介</a>
  207. <div class="price">
  208. <span class="iconfont icon-renminbi_o">14.9</span>
  209. <span>123人购买</span>
  210. </div>
  211. </div>
  212. </li>
  213. <li class="item">
  214. <!-- 图片 -->
  215. <a href=""><img src="images/items/item-18.webp" alt=""></a>
  216. <!-- 描述 -->
  217. <div class="desc">
  218. <a href="">商品简介商品简介商品简介</a>
  219. <div class="price">
  220. <span class="iconfont icon-renminbi_o">14.9</span>
  221. <span>123人购买</span>
  222. </div>
  223. </div>
  224. </li>
  225. <li class="item">
  226. <!-- 图片 -->
  227. <a href=""><img src="images/items/item-19.webp" alt=""></a>
  228. <!-- 描述 -->
  229. <div class="desc">
  230. <a href="">商品简介商品简介商品简介</a>
  231. <div class="price">
  232. <span class="iconfont icon-renminbi_o">14.9</span>
  233. <span>123人购买</span>
  234. </div>
  235. </div>
  236. </li>
  237. <li class="item">
  238. <!-- 图片 -->
  239. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  240. <!-- 描述 -->
  241. <div class="desc">
  242. <a href="">商品简介商品简介商品简介</a>
  243. <div class="price">
  244. <span class="iconfont icon-renminbi_o">14.9</span>
  245. <span>123人购买</span>
  246. </div>
  247. </div>
  248. </li>
  249. </ul>
  250. </main>
  251. <!-- 3. 页脚 -->
  252. <footer>
  253. <a href="m.taobao.com" class="iconfont icon-taobao"></a>
  254. <a href="">
  255. <span class="iconfont icon-gouwuche"></span>
  256. <span>购物车</span>
  257. </a>
  258. <a href="">
  259. <span class="iconfont icon-wode"></span>
  260. <span>我的淘宝</span>
  261. </a>
  262. </footer>
  263. </body>
  264. </html>

public CSS

  1. /* 页眉 */
  2. header,
  3. footer {
  4. height: 50px;
  5. /* 固定定位 */
  6. position: fixed;
  7. }
  8. header {
  9. background-color: #f4f4f4;
  10. /* 定位空间 */
  11. top: 0;
  12. left: 0;
  13. right: 0;
  14. /* z-index: 控制定位元素的显示层级 */
  15. z-index: 1;
  16. }
  17. footer {
  18. background-color: #f4f4f4;
  19. /* 页脚与页眉相比,只要把top,改为 bottom */
  20. bottom: 0;
  21. left: 0;
  22. right: 0;
  23. }
  24. main {
  25. /* background-color: yellow; */
  26. min-height: 2000px;
  27. /* overflow: hidden; */
  28. position: relative;
  29. top: 50px;
  30. }
  31. header {
  32. display: grid;
  33. grid-template-columns: 0.56rem 1fr 0.33rem;
  34. grid-auto-rows: 0.5rem;
  35. place-items: center;
  36. gap: 0.1rem;
  37. }
  38. header a.logo {
  39. padding-left: 0.1rem;
  40. }
  41. header>a.search {
  42. width: 100%;
  43. border: 2px solid #ff5000;
  44. height: 0.35rem;
  45. border-radius: 0.3rem;
  46. /* grid:整体 fiex:细节 */
  47. display: flex;
  48. place-content: space-between;
  49. place-items: center;
  50. }
  51. header>a.search>span:first-of-type {
  52. padding-left: 0.1rem;
  53. }
  54. header>a.search>span:last-of-type {
  55. /* background-color: #ff5000; */
  56. /* 渐变色:从左开始 */
  57. background: linear-gradient(to left, #ff5000, #ffa000);
  58. color: white;
  59. padding: 0.05rem 0.2rem;
  60. border-radius: 0.3rem;
  61. margin-right: 0.02rem;
  62. }
  63. header>a.iconfont {
  64. color: #ff5000;
  65. }
  66. /* 页脚 */
  67. footer {
  68. border-top: 1px solid #ccc;
  69. display: grid;
  70. grid-template-columns: repeat(3,1fr);
  71. place-content: space-around;
  72. place-items: center;
  73. font-size: smaller;
  74. }
  75. footer > a {
  76. display: grid;
  77. place-items: center;
  78. }
  79. footer > a:first-of-type {
  80. color: #f50;
  81. font-size: xx-large;
  82. }
  83. footer > a:first-of-type + a > span.iconfont {
  84. font-size: x-large;
  85. }

main CSS

  1. /* 主体样式 */
  2. main {
  3. min-height: 2000px;
  4. overflow: hidden;
  5. }
  6. /* 主体 顶部导航 */
  7. /* 顶部导航,快速入口,商品列表的public style */
  8. main .navs,
  9. main .entry,
  10. main .list > item {
  11. background-color: #fff;
  12. border-radius: 0.1rem;
  13. margin-top: 0.08rem;
  14. }
  15. main .navs {
  16. display: grid;
  17. /* 水平5列等宽 */
  18. grid-template-columns: repeat(5,1fr);
  19. gap: 0 10px;
  20. }
  21. main .navs .item {
  22. display: grid;
  23. place-items: center;
  24. }
  25. main .entry {
  26. display: grid;
  27. grid-template-columns: repeat(2,1fr);
  28. padding: 0.1rem;
  29. }
  30. main .entry .item {
  31. display: grid;
  32. grid-template-columns: repeat(2,1fr);
  33. padding: 0.1rem;
  34. }
  35. main .entry .item .title {
  36. grid-column: span 2;
  37. display: flex;
  38. place-items: center;
  39. }
  40. main .entry .item:nth-of-type(-n + 2){
  41. border-bottom: 1px solid #dedede;
  42. }
  43. main .entry .item span {
  44. background-color: #f50;
  45. color: white;
  46. border-radius: 0.03rem;
  47. font-size: smaller;
  48. padding: 0 0.03rem;
  49. margin-left: 0.05rem;
  50. }
  51. /* 商品列表 */
  52. main .list {
  53. display: grid;
  54. grid-template-columns: repeat(2,1fr);
  55. gap: 0 10px;
  56. }
  57. /* 商品图片圆角 */
  58. main .list .item img {
  59. border-radius: 0.1rem 0.1rem 0 0;
  60. }
  61. /* 商品描述 */
  62. main .list .item .desc {
  63. padding: 0.1rem;
  64. }
  65. /* 价格 */
  66. main .list .item .desc .iconfont {
  67. color: #f50;
  68. }
  69. main .list .item .price span:last-of-type {
  70. color: #bbb;
  71. font-style: x-small;
  72. }
上一条:首页更改后代码下一条:轮播图实例
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议