博客列表 >利用flex布局模仿某商城首页

利用flex布局模仿某商城首页

酿酒的人ァ
酿酒的人ァ原创
2021年03月28日 21:59:12688浏览

示例图

代码实例

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. <link rel="stylesheet" href="static/icon-font/iconfont.css" />
  8. <link rel="stylesheet" href="static/css/index.css" />
  9. <title>Document</title>
  10. </head>
  11. <body>
  12. <header>
  13. <!-- 小导航图标 -->
  14. <div class="menu iconfont icon-menu"></div>
  15. <!-- 搜索框 -->
  16. <div class="search">
  17. <div class="logo">JD</div>
  18. <div class="suosuo iconfont icon-search"></div>
  19. <input type="text" class="word" value="蛋糕" />
  20. </div>
  21. <a href="" class="login">登陆</a>
  22. </header>
  23. <div class="main">
  24. <div class="banner">
  25. <img src="static/images/bg/banner1.jpg" alt="" />
  26. </div>
  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-1.png" alt="" /></a>
  34. <a href="">京东超市</a>
  35. </li>
  36. <li>
  37. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  38. <a href="">京东超市</a>
  39. </li>
  40. <li>
  41. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  42. <a href="">京东超市</a>
  43. </li>
  44. <li>
  45. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  46. <a href="">京东超市</a>
  47. </li>
  48. <li>
  49. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  50. <a href="">京东超市</a>
  51. </li>
  52. <li>
  53. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  54. <a href="">京东超市</a>
  55. </li>
  56. <li>
  57. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  58. <a href="">京东超市</a>
  59. </li>
  60. <li>
  61. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  62. <a href="">京东超市</a>
  63. </li>
  64. <li>
  65. <a href="#"><img src="static/images/dh/nav-1.png" alt="" /></a>
  66. <a href="">京东超市</a>
  67. </li>
  68. </ul>
  69. <!-- 秒杀? -->
  70. <div class="ms">
  71. <div class="mstop">
  72. <div class="left">
  73. <div class="title">京东秒杀</div>
  74. <div class="notice">
  75. <div class="tips">22点专场</div>
  76. <div class="time">01:11:22</div>
  77. </div>
  78. </div>
  79. <div class="right">更多秒杀</div>
  80. </div>
  81. <ul class="miaoshi">
  82. <li class="neir">
  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">588</div>
  86. </li>
  87. <li class="neir">
  88. <a href="#"><img src="static/images/ms/ms-1.jpg" alt="" /></a>
  89. <div class="iconfont icon-rmb">338</div>
  90. <div class="iconfont icon-rmb">588</div>
  91. </li>
  92. <li class="neir">
  93. <a href="#"><img src="static/images/ms/ms-1.jpg" alt="" /></a>
  94. <div class="iconfont icon-rmb">338</div>
  95. <div class="iconfont icon-rmb">588</div>
  96. </li>
  97. </ul>
  98. </div>
  99. <div class="title">推荐商品</div>
  100. <ul class="tj">
  101. <li class="sp">
  102. <a href="#"><img src="static/images/sp/sp-1.webp" alt="" /></a>
  103. <p>这里是一个商品的介绍信息显示地方</p>
  104. <div class="xs">
  105. <div class="iconfont icon-rmb">100</div>
  106. <div>看相似</div>
  107. </div>
  108. </li>
  109. <li class="sp">
  110. <a href="#"><img src="static/images/sp/sp-1.webp" alt="" /></a>
  111. <p>这里是一个商品的介绍信息显示地方</p>
  112. <div class="xs">
  113. <div class="iconfont icon-rmb">100</div>
  114. <div>看相似</div>
  115. </div>
  116. </li>
  117. <li class="sp">
  118. <a href="#"><img src="static/images/sp/sp-1.webp" alt="" /></a>
  119. <p>这里是一个商品的介绍信息显示地方</p>
  120. <div class="xs">
  121. <div class="iconfont icon-rmb">100</div>
  122. <div>看相似</div>
  123. </div>
  124. </li>
  125. <li class="sp">
  126. <a href="#"><img src="static/images/sp/sp-1.webp" alt="" /></a>
  127. <p>这里是一个商品的介绍信息显示地方</p>
  128. <div class="xs">
  129. <div class="iconfont icon-rmb">100</div>
  130. <div>看相似</div>
  131. </div>
  132. </li>
  133. </ul>
  134. </div>
  135. <footer>
  136. <div>
  137. <div class="iconfont icon-home"></div>
  138. <span>首页</span>
  139. </div>
  140. <div>
  141. <div class="iconfont icon-layers"></div>
  142. <span>分类</span>
  143. </div>
  144. <div>
  145. <div class="iconfont icon-shopping-cart"></div>
  146. <span>购物车</span>
  147. </div>
  148. <div>
  149. <div class="iconfont icon-user"></div>
  150. <span>我的</span>
  151. </div>
  152. </footer>
  153. </body>
  154. </html>

CSS部分

  1. /* 导入公共初始化样式表 */
  2. @import "reset.css";
  3. /* 头部开始 */
  4. header {
  5. display: flex;
  6. align-items: center;
  7. background-color: #e43130;
  8. color: white;
  9. height: 4.4rem;
  10. position: fixed;
  11. top: 0;
  12. left: 0;
  13. right: 0;
  14. z-index: 100;
  15. font-size: 1.4rem;
  16. }
  17. header .menu {
  18. text-align: center;
  19. flex: 1;
  20. font-size: 2.5rem;
  21. }
  22. header .search {
  23. flex: 6;
  24. padding: 0.5rem;
  25. background-color: #fff;
  26. border-radius: 3rem;
  27. display: flex;
  28. }
  29. header .search .logo {
  30. color: #e43130;
  31. flex: 0 1 4rem;
  32. font-size: 2rem;
  33. text-align: center;
  34. line-height: 2rem;
  35. }
  36. header .search .suosuo {
  37. color: #ccc;
  38. flex: 0 1 2em;
  39. border-left: 1px solid;
  40. text-align: center;
  41. line-height: 2rem;
  42. }
  43. header .search .word {
  44. flex: auto;
  45. border: none;
  46. outline: none;
  47. color: #aaa;
  48. }
  49. header .login {
  50. color: #fff;
  51. text-align: center;
  52. flex: 1;
  53. }
  54. /* 头部结束 */
  55. /* 内容区暂定 */
  56. .main {
  57. position: absolute;
  58. top: 4.4rem;
  59. bottom: 4.4rem;
  60. left: 0;
  61. right: 0;
  62. font-size: 1.4rem;
  63. }
  64. .banner {
  65. margin: 1rem;
  66. }
  67. .banner img {
  68. height: 15rem;
  69. width: auto;
  70. border-radius: 2rem;
  71. }
  72. .main .nav {
  73. padding: 1rem;
  74. display: flex;
  75. flex-flow: row wrap;
  76. justify-content: space-between;
  77. }
  78. .main .nav li {
  79. flex: 1 1 20%;
  80. display: flex;
  81. flex-flow: column nowrap;
  82. align-items: center;
  83. }
  84. .main .nav img {
  85. height: 4rem;
  86. width: 4rem;
  87. }
  88. /* 秒杀 */
  89. .ms {
  90. background-color: #fff;
  91. padding: 1rem;
  92. margin: 1rem;
  93. border-radius: 2rem;
  94. }
  95. .mstop {
  96. font-size: 1.3rem;
  97. height: 3rem;
  98. display: flex;
  99. justify-content: space-between;
  100. }
  101. .left {
  102. display: flex;
  103. }
  104. .notice {
  105. font-size: 1.1rem;
  106. height: 2rem;
  107. border: 1px solid #e43130;
  108. border-radius: 2rem;
  109. margin-left: 1rem;
  110. display: flex;
  111. justify-content: center;
  112. align-items: center;
  113. }
  114. .tips {
  115. background-color: #e43130;
  116. color: #fff;
  117. border-radius: 2rem;
  118. padding: 0.3rem 0.5rem;
  119. }
  120. .time {
  121. padding: 0.3rem 0.5rem;
  122. }
  123. .right {
  124. color: #e43130;
  125. }
  126. .miaoshi {
  127. display: flex;
  128. justify-content: space-between;
  129. }
  130. .neir {
  131. display: flex;
  132. flex-direction: column;
  133. align-items: center;
  134. justify-content: center;
  135. }
  136. .neir img {
  137. height: 12rem;
  138. width: 12rem;
  139. }
  140. .main .ms .neir div:first-of-type {
  141. color: #e43130;
  142. font-weight: bolder;
  143. }
  144. .main .ms .neir div:last-of-type {
  145. color: #666666;
  146. text-decoration: line-through;
  147. text-decoration-color: #666666;
  148. }
  149. /* 商品? */
  150. .title {
  151. height: 4rem;
  152. color: #555;
  153. font-weight: 500;
  154. text-align: center;
  155. }
  156. .tj {
  157. font-size: 1rem;
  158. display: flex;
  159. flex-wrap: wrap;
  160. }
  161. .sp {
  162. flex: 1 1 calc(50% - 2rem);
  163. background-color: #fff;
  164. overflow: hidden;
  165. display: flex;
  166. flex-flow: column nowrap;
  167. padding: 1rem;
  168. margin-left: 1rem;
  169. margin-bottom: 1rem;
  170. padding-bottom: 1rem;
  171. border-radius: 1rem;
  172. }
  173. .sp img {
  174. width: 100%;
  175. height: 100%;
  176. }
  177. .xs {
  178. display: flex;
  179. justify-content: space-between;
  180. }
  181. .xs div:first-of-type {
  182. color: #e43130;
  183. }
  184. .xs div:last-of-type {
  185. color: #666;
  186. background-color: #f6f6f6;
  187. border-radius: 1rem;
  188. padding: 0.2rem 1rem;
  189. }
  190. /* 底部开始 */
  191. footer {
  192. display: flex;
  193. justify-content: space-around;
  194. align-items: center;
  195. color: #666;
  196. background-color: #fafafa;
  197. box-shadow: 0 0 3px #999;
  198. height: 4.4rem;
  199. position: fixed;
  200. bottom: 0;
  201. left: 0;
  202. right: 0;
  203. z-index: 100;
  204. font-size: 1.6rem;
  205. }
  206. footer div {
  207. display: flex;
  208. flex-flow: column nowrap;
  209. align-items: center;
  210. }
  211. footer div .iconfont {
  212. font-size: 2.4rem;
  213. }
  214. footer div .span {
  215. font-size: 1rem;
  216. }
  217. /* 底部结束 */
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议