博客列表 >使用flex仿写手机首页

使用flex仿写手机首页

L.E
L.E原创
2021年04月11日 23:50:00422浏览

仿手机首页效果图:

html

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>仿手机首页</title>
  7. <link rel="stylesheet" href="static/icon-font/iconfont.css" />
  8. <link rel="stylesheet" href="static/css/index.css" />
  9. <link rel="stylesheet" href="static/css/header.css" />
  10. <link rel="stylesheet" href="static/css/footer.css" />
  11. <link rel="stylesheet" href="static/css/nav.css" />
  12. <link rel="stylesheet" href="static/css/ms.css" />
  13. <link rel="stylesheet" href="static/css/tj.css" />
  14. </head>
  15. <body>
  16. <div class="header">
  17. <div class="menu iconfont icon-menu"></div>
  18. <div class="search">
  19. <div class="logo">JD</div>
  20. <div class="zoom iconfont icon-search"></div>
  21. <input type="text" class="words" value="电动自行车" />
  22. </div>
  23. <a href="" class="login">登录</a>
  24. </div>
  25. <div class="main">
  26. <!-- 主导航区 -->
  27. <ul class="nav">
  28. <li>
  29. <a href=""><img src="static/images/dh/nav-1.png" alt="" /></a>
  30. <a href="">京东超市</a>
  31. </li>
  32. <li>
  33. <a href=""><img src="static/images/dh/nav-2.png" alt="" /></a>
  34. <a href="">数码电器</a>
  35. </li>
  36. <li>
  37. <a href=""><img src="static/images/dh/nav-3.png" alt="" /></a>
  38. <a href="">京东服饰</a>
  39. </li>
  40. <li>
  41. <a href=""><img src="static/images/dh/nav-4.png" alt="" /></a>
  42. <a href="">京东生鲜</a>
  43. </li>
  44. <li>
  45. <a href=""><img src="static/images/dh/nav-5.png" alt="" /></a>
  46. <a href="">京东到家</a>
  47. </li>
  48. <li>
  49. <a href=""><img src="static/images/dh/nav-6.png" alt="" /></a>
  50. <a href="">充值缴费</a>
  51. </li>
  52. <li>
  53. <a href=""><img src="static/images/dh/nav-7.png" alt="" /></a>
  54. <a href="">9.9元拼</a>
  55. </li>
  56. <li>
  57. <a href=""><img src="static/images/dh/nav-8.png" alt="" /></a>
  58. <a href="">领券</a>
  59. </li>
  60. <li>
  61. <a href=""><img src="static/images/dh/nav-9.png" alt="" /></a>
  62. <a href="">领金贴</a>
  63. </li>
  64. <li>
  65. <a href=""><img src="static/images/dh/nav-10.png" alt="" /></a>
  66. <a href="">PLUS会员</a>
  67. </li>
  68. </ul>
  69. <div class="ms">
  70. <!-- 秒杀区 -->
  71. <div class="ms-top">
  72. <div class="left">
  73. <div class="title">京东秒杀</div>
  74. <div class="notice">
  75. <div class="tips">20点专场</div>
  76. <div class="time">01:04:33</div>
  77. </div>
  78. </div>
  79. <div class="right">更多秒杀</div>
  80. </div>
  81. <ul class="ms-body">
  82. <li class="item">
  83. <a href=""><img src="static/images/ms/ms-1.jpg" alt="" /></a>
  84. <div class="iconfont icon-rmb">338</div>
  85. <div class="iconfont icon-rmb">558</div>
  86. </li>
  87. <li class="item">
  88. <a href=""><img src="static/images/ms/ms-2.jpg" alt="" /></a>
  89. <div class="iconfont icon-rmb">3456</div>
  90. <div class="iconfont icon-rmb">4567</div>
  91. </li>
  92. <li class="item">
  93. <a href=""><img src="static/images/ms/ms-3.jpg" alt="" /></a>
  94. <div class="iconfont icon-rmb">789</div>
  95. <div class="iconfont icon-rmb">999</div>
  96. </li>
  97. <li class="item">
  98. <a href=""><img src="static/images/ms/ms-4.jpg" alt="" /></a>
  99. <div class="iconfont icon-rmb">3213</div>
  100. <div class="iconfont icon-rmb">4532</div>
  101. </li>
  102. </ul>
  103. </div>
  104. <!-- 推荐区 -->
  105. <ul class="tj">
  106. <li class="item">
  107. <a href=""><img src="static/images/sp/sp-1.webp" alt="" /></a>
  108. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介品介绍商品介绍</p>
  109. <div class="price">
  110. <div class="iconfont icon-rmb">203</div>
  111. <div>看相似</div>
  112. </div>
  113. </li>
  114. <li class="item">
  115. <a href=""><img src="static/images/sp/sp-2.webp" alt="" /></a>
  116. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介品介绍商品介绍</p>
  117. <div class="price">
  118. <div class="iconfont icon-rmb">203</div>
  119. <div>看相似</div>
  120. </div>
  121. </li>
  122. <li class="item">
  123. <a href=""><img src="static/images/sp/sp-3.webp" alt="" /></a>
  124. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介品介绍商品介绍</p>
  125. <div class="price">
  126. <div class="iconfont icon-rmb">203</div>
  127. <div>看相似</div>
  128. </div>
  129. </li>
  130. <li class="item">
  131. <a href=""><img src="static/images/sp/sp-4.webp" alt="" /></a>
  132. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介品介绍商品介绍</p>
  133. <div class="price">
  134. <div class="iconfont icon-rmb">203</div>
  135. <div>看相似</div>
  136. </div>
  137. </li>
  138. <li class="item">
  139. <a href=""><img src="static/images/sp/sp-5.webp" alt="" /></a>
  140. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介品介绍商品介绍</p>
  141. <div class="price">
  142. <div class="iconfont icon-rmb">203</div>
  143. <div>看相似</div>
  144. </div>
  145. </li>
  146. <li class="item">
  147. <a href=""><img src="static/images/sp/sp-6.webp" alt="" /></a>
  148. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商品介品介绍商品介绍</p>
  149. <div class="price">
  150. <div class="iconfont icon-rmb">203</div>
  151. <div>看相似</div>
  152. </div>
  153. </li>
  154. </ul>
  155. </div>
  156. </div>
  157. <div class="footer">
  158. <div>
  159. <div class="iconfont icon-home"></div>
  160. <span>首页</span>
  161. </div>
  162. <div>
  163. <div class="iconfont icon-layers"></div>
  164. <span>分类</span>
  165. </div>
  166. <div>
  167. <div class="iconfont icon-kehuguanli"></div>
  168. <span>京喜</span>
  169. </div>
  170. <div>
  171. <div class="iconfont icon-shopping-cart"></div>
  172. <span>购物车</span>
  173. </div>
  174. <div>
  175. <div class="iconfont icon-user"></div>
  176. <span>未登录</span>
  177. </div>
  178. </div>
  179. </body>
  180. </html>

index.css

  1. /* 导入公共初始化样式表 */
  2. @import "reset.css";
  3. .header {
  4. background-color: #e43130;
  5. color: white;
  6. height: 3.6rem;
  7. position: fixed;
  8. top: 0;
  9. left: 0;
  10. right: 0;
  11. z-index: 100;
  12. font-size: 1.2rem;
  13. }
  14. .footer {
  15. color: #666;
  16. background-color: #fafafa;
  17. box-shadow: 0 0 3px #999;
  18. height: 4.4rem;
  19. position: fixed;
  20. bottom: 0;
  21. left: 0;
  22. right: 0;
  23. z-index: 100;
  24. font-size: 1.4rem;
  25. }
  26. .main {
  27. position: absolute;
  28. top: 4.4rem;
  29. bottom: 4.4rem;
  30. left: 0;
  31. right: 0;
  32. font-size: 1.4rem;
  33. }

reset.css

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. li {
  7. list-style: none;
  8. }
  9. a {
  10. color: #7b7b7b;
  11. text-decoration: none;
  12. }
  13. body {
  14. background-color: #F6F6F6;
  15. }
  16. html {
  17. font-size: 10px;
  18. }
  19. /* 媒体查询 */
  20. @media screen and (min-width: 480px) {
  21. html {
  22. font-size: 12px;
  23. }
  24. }
  25. @media screen and (min-width: 640px) {
  26. html {
  27. font-size: 14px;
  28. }
  29. }
  30. @media screen and (min-width: 720px) {
  31. html {
  32. font-size: 16px;
  33. }
  34. }

header.css

  1. .header {
  2. display: flex;
  3. flex-flow: row nowrap;
  4. align-items: center;
  5. }
  6. .header .login {
  7. color: #fff;
  8. text-align: center;
  9. flex: 1;
  10. }
  11. .header .menu {
  12. text-align: center;
  13. flex: 1;
  14. font-size: 2rem;
  15. }
  16. .header .search {
  17. flex: 7;
  18. padding: 0.5rem;
  19. background-color: #fff;
  20. border-radius: 3rem;
  21. display: flex;
  22. }
  23. .header .search .logo {
  24. color: #e43130;
  25. flex: 0 1 3rem;
  26. font-size: 1.5rem;
  27. text-align: center;
  28. line-height: 1.5rem;
  29. font-weight: bold;
  30. }
  31. .header .search .zoom {
  32. color: #ccc;
  33. flex: 0 1 3rem;
  34. border-left: 1px solid;
  35. text-align: center;
  36. line-height: 1.5rem;
  37. }
  38. .header .search .words {
  39. flex: auto;
  40. border: none;
  41. outline: none;
  42. color: #aaa;
  43. }

footer.css

  1. .footer {
  2. display: flex;
  3. justify-content: space-around;
  4. align-items: center;
  5. }
  6. .footer > div {
  7. display: flex;
  8. flex-flow: column nowrap;
  9. align-items: center;
  10. }
  11. .footer > div > .iconfont {
  12. font-size: 2rem;
  13. }
  14. .footer > div > span {
  15. font-size: 1rem;
  16. }
  17. .footer > div {
  18. cursor: pointer;
  19. }

nav.css

  1. .main .nav {
  2. padding: 0.5rem;
  3. display: flex;
  4. flex-flow: row wrap;
  5. justify-content: space-between;
  6. }
  7. .main .nav img {
  8. height: 4rem;
  9. width: 4rem;
  10. }
  11. .main .nav li {
  12. flex: 1 1 20%;
  13. display: flex;
  14. flex-flow: column nowrap;
  15. align-items: center;
  16. }

ms.css

  1. .main .ms .ms-body {
  2. display: flex;
  3. justify-content: space-between;
  4. }
  5. .main .ms .ms-body img {
  6. height: 12rem;
  7. width: 12rem;
  8. }
  9. .main .ms .ms-body .item div:first-of-type {
  10. color: #e43130;
  11. font-weight: bolder;
  12. }
  13. .main .ms .ms-body .item div:last-of-type {
  14. color: #666666;
  15. text-decoration: line-through;
  16. text-decoration-color: #666666;
  17. }

tj.css

  1. .main .tj {
  2. font-size: 1.1rem;
  3. color: #555;
  4. display: flex;
  5. flex-flow: row wrap;
  6. justify-content: center;
  7. }
  8. .main .tj .item {
  9. flex-basis: calc(50% - 3rem);
  10. padding: 1rem;
  11. background-color: #fff;
  12. overflow: hidden;
  13. display: flex;
  14. flex-flow: column nowrap;
  15. margin-left: 1rem;
  16. margin-bottom: 1rem;
  17. border-radius: 1rem;
  18. }
  19. .main .tj .item img {
  20. width: 100%;
  21. height: 100%;
  22. }
  23. .main .tj .item {
  24. padding: 1rem;
  25. }
  26. .main .tj .item .price {
  27. display: flex;
  28. justify-content: space-between;
  29. }
  30. .main .tj .item .price div:first-of-type {
  31. color: red;
  32. font-weight: bolder;
  33. }
  34. .main .tj .item .price div:last-of-type {
  35. background-color: #f6f6f6;
  36. border-radius: 1rem;
  37. padding: 0.2rem 1rem;
  38. color: #666;
  39. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议