博客列表 >使用定位、flex与grid布局仿酒仙网手机端页面

使用定位、flex与grid布局仿酒仙网手机端页面

樱风醉
樱风醉原创
2021年10月10日 16:57:37675浏览

仿酒仙网https://m.jiuxian.com/,点击链接查看正版网站

1.各部分css样式

①重置样式

  1. /* 样式重置 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* 链接 */
  8. a {
  9. text-decoration: none;
  10. color: #666;
  11. }
  12. /* 列表 */
  13. li {
  14. list-style: none;
  15. }
  16. :root {
  17. font-size: 10px;
  18. }
  19. body {
  20. font-size: 1.6rem;
  21. /* 有一个浅灰色背景 */
  22. background-color: #f6f6f6;
  23. }
  24. /* 用媒体查询来动态设置字号,使在较小的手机屏幕上也能看清字号 */
  25. @media screen and (min-width: 480px) {
  26. :root {
  27. font-size: 12px;
  28. }
  29. }
  30. @media screen and (min-width: 640px) {
  31. :root {
  32. font-size: 14px;
  33. }
  34. }
  35. @media screen and (min-width: 720px) {
  36. :root {
  37. font-size: 16px;
  38. }
  39. }

②顶部APP下载部分

  1. .app-download {
  2. width: 100%;
  3. height: 4.3rem;
  4. background-color: #2e2e2e;
  5. margin: 0 auto 0;
  6. display: flex;
  7. justify-content: center;
  8. align-items: center;
  9. }
  10. .app-download .icon-guanbi {
  11. color: white;
  12. font-size: 1.6rem;
  13. margin: 0 1.4rem;
  14. }
  15. .app-download img {
  16. width: 3rem;
  17. height: 3rem;
  18. }
  19. .app-download h3 {
  20. margin: 0 4rem 0 5rem;
  21. text-align: center;
  22. }
  23. .app-download h3 p {
  24. color: white;
  25. font-size: 1rem;
  26. white-space: nowrap;
  27. }
  28. .app-download a {
  29. font-size: 1.4rem;
  30. background-color: #e62929;
  31. color: white;
  32. width: 12rem;
  33. height: 4.3rem;
  34. margin-left: auto;
  35. line-height: 43px;
  36. text-align: center;
  37. }

③头部logo及搜索框

  1. .header {
  2. width: 100%;
  3. height: 4rem;
  4. display: flex;
  5. justify-content: space-between;
  6. align-items: center;
  7. background-color: #e5383b;
  8. position: sticky;
  9. top: 0;
  10. left: 0;
  11. }
  12. .header a img {
  13. width: 5.7rem;
  14. height: 2.7rem;
  15. margin-left: 1rem;
  16. }
  17. .header .search {
  18. background-color: white;
  19. width: 29rem;
  20. height: 2.7rem;
  21. display: flex;
  22. align-items: center;
  23. border-radius: 0.5rem;
  24. margin: 0 0.5rem 0 0.6rem;
  25. }
  26. .header .search form input {
  27. width: 100%;
  28. height: 2.7rem;
  29. outline: none;
  30. border: none;
  31. color: #888;
  32. }
  33. .header .search .icon-sousuo {
  34. color: #e43130;
  35. font-size: 1.2rem;
  36. padding: 0 0.5rem;
  37. margin: 0 0.8rem;
  38. }

④轮播图

  1. .slider {
  2. width: 100%;
  3. margin: 0 auto 2rem;
  4. }
  5. .slider img {
  6. width: 100%;
  7. height: 100%;
  8. border-radius: 0 0 1rem 1rem;
  9. }
  10. .slider .imgs a {
  11. display: none;
  12. }
  13. /* 默认第一个轮播图激活 */
  14. .slider .imgs a.active {
  15. display: block;
  16. }
  17. /* 切换按钮容器的样式 */
  18. .slider .btns {
  19. /* flex布局,且水平居中,并上移到轮播图底部 */
  20. display: flex;
  21. justify-content: flex-end;
  22. /* 负外距可反向移动元素,这里是向上 */
  23. margin-top: -2rem;
  24. margin-right: 1rem;
  25. }
  26. /* 切换按钮 */
  27. .slider .btns .item {
  28. height: 0.8rem;
  29. width: 0.8rem;
  30. border-radius: 50%;
  31. background-color: #888;
  32. margin: 0.2rem;
  33. }
  34. /* 切换按钮鼠标悬停样式 */
  35. .slider .btns .item:hover {
  36. cursor: pointer;
  37. }
  38. /* 当前默认激活的按钮样式 */
  39. .slider .btns .item.active {
  40. background-color: #e43130;
  41. }

⑤导航栏

  1. .navs {
  2. width: 100%;
  3. background-color: white;
  4. display: grid;
  5. grid-template-rows: repeat(2, 1fr);
  6. grid-template-columns: repeat(5, 1fr);
  7. place-content: center;
  8. }
  9. .navs a img {
  10. width: 7.7rem;
  11. }

⑥banner图/新闻/秒杀

  1. /* 导航下方banner图 */
  2. .pubBanner a img {
  3. width: 100%;
  4. }
  5. /* 滚动新闻 */
  6. .news {
  7. padding: 0.8rem 1rem;
  8. }
  9. .news i {
  10. width: 8.3rem;
  11. height: 1.6rem;
  12. padding: 0.2rem 1rem 0.2rem 0;
  13. border-right: 1px solid #e4c5c5;
  14. padding-right: 10px;
  15. }
  16. .news i img {
  17. width: 83px;
  18. height: 16px;
  19. }
  20. .news a {
  21. font-size: 1.2rem;
  22. margin-left: 1.5rem;
  23. }
  24. /* 秒杀 */
  25. .spikeBox .spike {
  26. height: 3rem;
  27. display: flex;
  28. justify-content: space-around;
  29. }
  30. .spikeBox .spike h3 {
  31. font-size: 1.4rem;
  32. font-weight: bolder;
  33. font-family: "黑体";
  34. }
  35. .spikeBox .spike a,
  36. .spikeBox .spike .iconfont,
  37. .spikeBox .spike .lastTime,
  38. .spikeBox .shop .item .name,
  39. .spikeBox .shop .item .y-price {
  40. font-size: 1.2rem;
  41. }
  42. .spikeBox .shop .item .y-price {
  43. font-size: 1.2rem;
  44. color: #999;
  45. }
  46. .spikeBox .shop {
  47. background-color: #fff;
  48. display: flex;
  49. justify-content: space-evenly;
  50. }
  51. .spikeBox .shop .item {
  52. padding: 0 1rem;
  53. display: flex;
  54. flex-direction: column;
  55. justify-content: center;
  56. }
  57. .spikeBox .shop .item img {
  58. width: 10rem;
  59. }
  60. .spikeBox .shop .item .price {
  61. font-size: 1.4rem;
  62. color: #fc5a5a;
  63. }

⑦活动广告

  1. .ad {
  2. width: 100%;
  3. background-color: white;
  4. margin: 1rem 0;
  5. display: grid;
  6. grid-template-columns: 1fr 1fr;
  7. grid-template-rows: 1fr 1fr;
  8. place-content: center;
  9. }
  10. .ad img:first-of-type {
  11. width: 18rem;
  12. grid-area: 1/1/3/2;
  13. }
  14. .ad img:nth-of-type(n + 2) {
  15. width: 18rem;
  16. }

⑧商品列表

  1. .list {
  2. width: 100%;
  3. background-color: #fff;
  4. }
  5. .list ul {
  6. display: grid;
  7. grid-template-columns: repeat(2, 1fr);
  8. gap: 0.5rem;
  9. padding: 1.2rem;
  10. justify-content: space-evenly;
  11. }
  12. .list ul li {
  13. display: flex;
  14. flex-direction: column;
  15. }
  16. .list .title {
  17. width: 100%;
  18. height: 3.3rem;
  19. background-color: #fff;
  20. margin-top: 2rem;
  21. border-top: 1px solid #f5e7e7;
  22. border-bottom: 1px solid #f5e7e7;
  23. text-align: center;
  24. }
  25. .list .title a {
  26. line-height: 3.3rem;
  27. height: 3.3rem;
  28. color: #666666;
  29. font-size: 1.2rem;
  30. }
  31. .list ul li .tag {
  32. width: 7rem;
  33. height: 1.6rem;
  34. text-align: center;
  35. line-height: 1.6rem;
  36. border-radius: 0.3rem;
  37. padding: 0 0.5rem;
  38. font-size: 1.2rem;
  39. color: #fff;
  40. }
  41. .list ul li .red {
  42. background-color: #ff6266;
  43. }
  44. .list ul li .yel {
  45. background-color: #ffa855;
  46. }
  47. .list ul li .blue {
  48. background-color: #8888ff;
  49. }
  50. .list ul li a img {
  51. width: 17rem;
  52. align-self: center;
  53. }
  54. .list ul li .name {
  55. height: 3.2rem;
  56. font-size: 1.2rem;
  57. line-height: 1.6rem;
  58. }
  59. .list ul li .price .x-price {
  60. color: #fc5a5a;
  61. font-size: 1.4rem;
  62. }
  63. .list ul li .price .y-price {
  64. color: #999;
  65. font-size: 1.2rem;
  66. margin-left: 0.5rem;
  67. }

⑨版权/联系方式

  1. .copyright {
  2. height: 8rem;
  3. width: 100%;
  4. text-align: center;
  5. line-height: 2rem;
  6. color: rgb(153, 153, 153);
  7. font-size: 1.2rem;
  8. padding: 1rem 0 5rem;
  9. margin-bottom: 6rem;
  10. }

⑩页脚菜单

  1. .footer {
  2. width: 100%;
  3. height: 42px;
  4. display: flex;
  5. justify-content: space-around;
  6. border-top: 1px solid #cccccc;
  7. background: #f1f1f1;
  8. position: fixed;
  9. bottom: 0;
  10. left: 0;
  11. right: 0;
  12. z-index: 999;
  13. }
  14. .footer a img {
  15. width: 4.2rem;
  16. }

2.html代码

  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. <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/appDownload.css" />
  11. <link rel="stylesheet" href="css/header.css" />
  12. <link rel="stylesheet" href="css/slider.css" />
  13. <link rel="stylesheet" href="css/nav.css" />
  14. <link rel="stylesheet" href="css/banner_news_spike.css" />
  15. <link rel="stylesheet" href="css/ad.css" />
  16. <link rel="stylesheet" href="css/list.css" />
  17. <link rel="stylesheet" href="css/copyright.css" />
  18. <link rel="stylesheet" href="css/footer.css" />
  19. </head>
  20. <body>
  21. <!-- 酒仙网APP下载 -->
  22. <div class="app-download">
  23. <span class="iconfont icon-guanbi"></span>
  24. <img src="img/topApp.png" />
  25. <h3>
  26. <p>打开酒仙网APP</p>
  27. <p>新人领198元礼包</p>
  28. </h3>
  29. <a href="https://m.jiuxian.com/">立即打开</a>
  30. </div>
  31. <!-- 头部搜索框 -->
  32. <div class="header">
  33. <a href="https://m.jiuxian.com/"><img src="img/jx-sprite.png" /></a>
  34. <div class="search">
  35. <span class="iconfont icon-sousuo"></span>
  36. <form action="">
  37. <input type="search" name="search" value="错峰抢购 三档好礼满赠" />
  38. </form>
  39. </div>
  40. </div>
  41. <!-- 轮播图 -->
  42. <div class="slider">
  43. <div class="imgs">
  44. <a href="" class="active"><img src="img/slider/s1.jpg" alt="" /></a>
  45. <a href=""><img src="img/slider/s2.jpg" alt="" /></a>
  46. <a href=""><img src="img/slider/s3.jpg" alt="" /></a>
  47. <a href=""><img src="img/slider/s4.jpg" alt="" /></a>
  48. </div>
  49. <!-- 轮播图底部的切换按钮组,与轮播图数量对应 -->
  50. <div class="btns">
  51. <span class="item active"></span>
  52. <span class="item"></span>
  53. <span class="item"></span>
  54. <span class="item"></span>
  55. </div>
  56. </div>
  57. <!-- 导航区 -->
  58. <div class="navs">
  59. <a href=""><img src="img/nav/baijiu.jpg" alt="" /></a>
  60. <a href=""><img src="img/nav/putaojiu.jpg" alt="" /></a>
  61. <a href=""><img src="img/nav/zhibo.gif" alt="" /></a>
  62. <a href=""><img src="img/nav/yangjiu.jpg" alt="" /></a>
  63. <a href=""><img src="img/nav/pijiu.jpg" alt="" /></a>
  64. <a href=""><img src="img/nav/mendian.jpg" alt="" /></a>
  65. <a href=""><img src="img/nav/club.jpg" alt="" /></a>
  66. <a href=""><img src="img/nav/19fen.gif" alt="" /></a>
  67. <a href=""><img src="img/nav/yaohzan.gif" alt="" /></a>
  68. <a href=""><img src="img/nav/pintuan.jpg" alt="" /></a>
  69. </div>
  70. <!-- 活动banner图 -->
  71. <div class="pubBanner">
  72. <a href=""><img src="img/banner/banner01.jpg" alt="" /></a>
  73. </div>
  74. <!-- 新闻 -->
  75. <div class="news">
  76. <i>
  77. <img src="img/news/t1.jpg" alt="" />
  78. </i>
  79. <a href="">1499飞天茅台限量抢</a>
  80. </div>
  81. <!-- 秒杀 -->
  82. <div class="spikeBox">
  83. <div class="spike">
  84. <h3>掌上秒拍</h3>
  85. <div class="lastTime">
  86. <span>距结束</span>
  87. <span class="hours">02</span><b>:</b><span class="minutes">15</span><b>:</b><span class="seconds">57</span>
  88. </div>
  89. <a href=""><span>更多商品的你来抢!</span><span class="iconfont icon-youjiantou-tianchong"></span></a>
  90. </div>
  91. <div class="shop">
  92. <div class="item">
  93. <img src="img/shop/1.jpg" />
  94. <span class="name">52°扳倒井好品天下480ml *6整箱装</span>
  95. <span class="price">¥99.00</span>
  96. <del class="y-price">¥174.00</del>
  97. </div>
  98. <div class="item">
  99. <img src="img/shop/2.jpg" />
  100. <span class="name">40°人头马VSOP干邑白兰地(乐享)50ml</span>
  101. <span class="price">¥418.00</span>
  102. <del class="y-price">¥499.00</del>
  103. </div>
  104. <div class="item">
  105. <img src="img/shop/3.jpg" />
  106. <span class="name">52° 洋河蓝色经典 海之蓝1000ml*1</span>
  107. <span class="price">¥279.00</span>
  108. <del class="y-price">¥359.00</del>
  109. </div>
  110. </div>
  111. </div>
  112. <!-- 活动banner图 -->
  113. <div class="pubBanner">
  114. <a href=""><img src="img/banner/banner001.jpg" alt="" /></a>
  115. </div>
  116. <div class="pubBanner">
  117. <a href=""><img src="img/banner/banner002.jpg" alt="" /></a>
  118. </div>
  119. <div class="pubBanner">
  120. <a href=""><img src="img/banner/banner003.jpg" alt="" /></a>
  121. </div>
  122. <!-- 活动广告 -->
  123. <div class="ad">
  124. <img src="img/ads/1.jpg" alt="" />
  125. <img src="img/ads/2.jpg" alt="" />
  126. <img src="img/ads/3.jpg" alt="" />
  127. </div>
  128. <!-- 爆款推荐 -->
  129. <div class="list">
  130. <div class="title">
  131. <a href="">爆款推荐</a>
  132. </div>
  133. <ul>
  134. <li>
  135. <span class="tag red">手机专享价</span>
  136. <a href=""><img src="img/shop/01.jpg" alt="" /></a>
  137. <span class="name">43°茅台飞天500ml</span>
  138. <div class="price">
  139. <span class="x-price"><strong>¥1029.00</strong></span>
  140. <del class="y-price">¥1399.00</del>
  141. </div>
  142. </li>
  143. <li>
  144. <span class="tag red">手机专享价</span>
  145. <a href=""><img src="img/shop/02.jpg" alt="" /></a>
  146. <span class="name">澳大利亚黄尾袋鼠加本力梅洛红葡萄酒6支装</span>
  147. <div class="price">
  148. <span class="x-price"><strong>¥258.00</strong></span>
  149. <del class="y-price">¥348.00</del>
  150. </div>
  151. </li>
  152. <li>
  153. <span class="tag red">掌上秒拍</span>
  154. <a href=""><img src="img/shop/03.jpg" alt="" /></a>
  155. <span class="name">53度赖茅传禧500ml(2瓶)</span>
  156. <div class="price">
  157. <span class="x-price"><strong>¥388.00</strong></span>
  158. <del class="y-price">¥498.00</del>
  159. </div>
  160. </li>
  161. <li>
  162. <div>
  163. <span class="tag yel">限时抢购</span>
  164. <span class="tag blue">满赠</span>
  165. </div>
  166. <a href=""><img src="img/shop/04.jpg" alt="" /></a>
  167. <span class="name">55°汾酒盘古汾酒500ml(2019版)*4</span>
  168. <div class="price">
  169. <span class="x-price"><strong>¥1000.00</strong></span>
  170. <del class="y-price">¥1596.00</del>
  171. </div>
  172. </li>
  173. <li>
  174. <span class="tag yel">限时抢购</span>
  175. <a href=""><img src="img/shop/05.jpg" alt="" /></a>
  176. <span class="name">40°法国马爹利鼎盛干邑白兰地500ml+鼎盛50ml*2</span>
  177. <div class="price">
  178. <span class="x-price"><strong>¥230.00</strong></span>
  179. <del class="y-price">¥437.00</del>
  180. </div>
  181. </li>
  182. <li>
  183. <div>
  184. <span class="tag yel">限时抢购</span>
  185. <span class="tag blue">满减</span>
  186. <span class="tag blue">单品加价购</span>
  187. </div>
  188. <a href=""><img src="img/shop/06.jpg" alt="" /></a>
  189. <span class="name">五虎上将【中华老字号】白水杜康 52度浓香型白酒 500ml*5瓶整箱*4</span>
  190. <div class="price">
  191. <span class="x-price"><strong>¥128.00</strong></span>
  192. <del class="y-price">¥598.00</del>
  193. </div>
  194. </li>
  195. <li>
  196. <div>
  197. <span class="tag yel">限时抢购</span>
  198. <span class="tag blue">满减</span>
  199. <span class="tag blue">买赠</span>
  200. </div>
  201. <a href=""><img src="img/shop/07.jpg" alt="" /></a>
  202. <span class="name">53°习酒窖藏1988雅致版(新款)500ml</span>
  203. <div class="price">
  204. <span class="x-price"><strong>¥718.00</strong></span>
  205. <del class="y-price">¥869.00</del>
  206. </div>
  207. </li>
  208. <li>
  209. <div>
  210. <span class="tag yel">抄底价</span>
  211. <span class="tag blue">多买多赠</span>
  212. </div>
  213. <a href=""><img src="img/shop/08.jpg" alt="" /></a>
  214. <span class="name">53°贵州金沙古酱酒 酱香型 500ml单瓶装尊贵蓝</span>
  215. <div class="price">
  216. <span class="x-price"><strong>¥148.00</strong></span>
  217. <del class="y-price">¥268.00</del>
  218. </div>
  219. </li>
  220. </ul>
  221. </div>
  222. <!-- 版权信息 -->
  223. <div class="copyright">
  224. <p>酒仙网络科技股份有限公司版权所有</p>
  225. <p>北京市北京经济技术开发区经海五路58号院8幢1-6层</p>
  226. <p><span>400-617-9999</span></p>
  227. <p><a href="https://m.jiuxian.com/mobile/2016/about/index.html" style="color: #0088ff">关于我们</a></p>
  228. </div>
  229. <!-- 页脚菜单 -->
  230. <div class="footer">
  231. <a href=""><img src="img/shouye.png" alt="" /></a>
  232. <a href=""><img src="img/fenlei.png" alt="" /></a>
  233. <a href=""><img src="img/jinbao.png" alt="" /></a>
  234. <a href=""><img src="img/gouwuche.png" alt="" /></a>
  235. <a href=""><img src="img/wode.png" alt="" /></a>
  236. </div>
  237. </body>
  238. </html>

3.效果图



声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议