博客列表 >仿京东商城(移动端)小案例

仿京东商城(移动端)小案例

李东亚¹⁸⁰³⁹⁵⁴⁰¹²⁰
李东亚¹⁸⁰³⁹⁵⁴⁰¹²⁰原创
2020年12月25日 22:42:391692浏览

一、分析JD商城移动端页面布局

1、布局拆分页眉(头部)、主体(内容区)、底部(页脚)
2、头部和尾部用绝对定位,固定
3、主题部分有内容撑开设置overflow属性auto;
4、主题可以分为幻灯片、导航区、商品展示区,基本上都可以通过flex设置自适应布局
5、css重置样式表、布局样式表、头部和尾部以及主题样式

二、实战案例

1、代码部分:
1.1、html代码:

  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>仿京东移动端案例</title>
  8. <link rel="stylesheet" href="static/style/layout.css">
  9. <link rel="stylesheet" href="static/font/iconfont.css">
  10. <link rel="stylesheet" href="static/style/header.css">
  11. <link rel="stylesheet" href="static/style/main.css">
  12. <link rel="stylesheet" href="static/style/footer.css">
  13. </head>
  14. <body>
  15. <header>
  16. <span class="iconfont icon-category"></span>
  17. <div class="search">
  18. <span>JD</span>
  19. <span class="iconfont icon-search"></span>
  20. <input type="search" value="三星硬盘">
  21. </div>
  22. <span><a href="">登陆</a></span>
  23. </header>
  24. <main>
  25. <div>
  26. <div class="banner">
  27. <img src="static/images/banner.jpg" >
  28. </div>
  29. </div>
  30. <div class="slider">
  31. <img src="static/images/bgc%20(2).jpg" alt="">
  32. <img src="static/images/bgc%20(1).jpg" alt="">
  33. <img src="static/images/bgc%20(3).jpg" alt="">
  34. </div>
  35. <nav>
  36. <div><img src="static/images/京东超市.png" alt=""><span>京东超市</span></div>
  37. <div><img src="static/images/数码电器.png" alt=""><span>数码电器</span></div>
  38. <div><img src="static/images/京东服饰.png" alt=""><span>京东服饰</span></div>
  39. <div><img src="static/images/京东生鲜.png" alt=""><span>京东生鲜</span></div>
  40. <div><img src="static/images/京东到家.png" alt=""><span>京东到家</span></div>
  41. <div><img src="static/images/9.9元拼.png" alt=""><span>9.9元拼</span></div>
  42. <div><img src="static/images/领卷.png" alt=""><span>领卷</span></div>
  43. <!-- <div><img src="static/images/借钱.png" alt=""><span>借钱</span></div> -->
  44. <div><img src="static/images/PLUS会员.png" alt=""/><span>PLUS会员</span></div>
  45. <div><img src="static/images/充值缴费.png" alt=""><span>充值缴费</span></div>
  46. <div><img src="static/images/领金贴.png" alt=""><span>领金贴</span></div>
  47. </nav>
  48. <div class="ms">
  49. <div>
  50. <img src="static/images/products%20(3).jpg" alt="">
  51. <span>满499减150</span>
  52. <span>双旦礼遇季</span>
  53. </div>
  54. <div>
  55. <img src="static/images/products%20(4).jpg" alt="">
  56. <span>满499减150</span>
  57. <span>双旦礼遇季</span>
  58. </div>
  59. <div>
  60. <img src="static/images/products%20(3).jpg" alt="">
  61. <span>满499减150</span>
  62. <span>双旦礼遇季</span>
  63. </div>
  64. <div>
  65. <img src="static/images/products%20(4).jpg" alt="">
  66. <span>满499减150</span>
  67. <span>双旦礼遇季</span>
  68. </div>
  69. </div>
  70. <div class="shop">
  71. <img src="static/images/guess-like.png" alt="">
  72. <div class="shop-detail">
  73. <div>
  74. <img src="static/images/products%20(2).jpg" alt="">
  75. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商</p>
  76. <div><span>&yen;89</span> <span>看相似</span></div>
  77. </div>
  78. <div>
  79. <img src="static/images/products%20(2).jpg" alt="">
  80. <p>商品介绍商品介绍商品介绍商品介绍商品介绍</p>
  81. <div><span>&yen;89</span> <span>看相似</span></div>
  82. </div>
  83. <div>
  84. <img src="static/images/products%20(2).jpg" alt="">
  85. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品</p>
  86. <div><span>&yen;89</span> <span>看相似</span></div>
  87. </div>
  88. <div>
  89. <img src="static/images/products%20(2).jpg" alt="">
  90. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品</p>
  91. <div><span>&yen;89</span> <span>看相似</span></div>
  92. </div>
  93. <div>
  94. <img src="static/images/products%20(2).jpg" alt="">
  95. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍</p>
  96. <div><span>&yen;89</span> <span>看相似</span></div>
  97. </div>
  98. <div>
  99. <img src="static/images/products%20(2).jpg" alt="">
  100. <p>商品介绍商品介绍商品介绍商品介绍商品介绍商品介绍商</p>
  101. <div><span>&yen;89</span> <span>看相似</span></div>
  102. </div>
  103. </div>
  104. </div>
  105. </main>
  106. <footer>
  107. <a href=""><img src="static/images/icon%20(4).png" alt=""></a>
  108. <a href=""><img src="static/images/icon%20(1).png" alt=""></a>
  109. <a href=""><img src="static/images/icon%20(3).png" alt=""></a>
  110. <a href=""><img src="static/images/icon%20(5).png" alt=""></a>
  111. <a href=""><img src="static/images/icon%20(2).png" alt=""></a>
  112. </footer>
  113. </body>
  114. </html>

1.2、css样式:

  1. /*重置样式*/
  2. *{
  3. padding: 0;
  4. margin: 0;
  5. box-sizing: border-box;
  6. border: none;
  7. }
  8. ul{
  9. list-style: none;
  10. }
  11. a{
  12. text-decoration: none;
  13. }
  14. html{
  15. font-size: 10px;
  16. }
  17. body{
  18. background-color: #f6f6f6;
  19. }
  20. /* 布局 */
  21. @import url("resetCSS.css");
  22. header{
  23. height:5rem ;
  24. background-color: #c72518;
  25. color:#FFFFFF;
  26. position: fixed;
  27. top:0;
  28. left: 0;
  29. right:0;
  30. }
  31. footer{
  32. height:5rem ;
  33. background-color: #fff;
  34. position: fixed;
  35. bottom:0;
  36. left: 0;
  37. right:0;
  38. }
  39. main{
  40. position: fixed;
  41. top:5rem;
  42. left:0;
  43. right:0;
  44. bottom: 5rem;
  45. overflow: auto;
  46. }
  47. /* 头部样式 */
  48. @import url("resetCSS.css");
  49. header{
  50. display: flex;
  51. justify-content: space-between;
  52. /* font-size: 1.6rem; */
  53. align-items: center;
  54. /* padding:0 0.8rem ; */
  55. }
  56. header > .search{
  57. background-color: #fff;
  58. height: 2.9rem;
  59. border-radius: 2rem;
  60. flex:8;
  61. padding: 0 1.2rem;
  62. }
  63. header > span {
  64. width: 5.5rem;
  65. font-size: 1.4rem;
  66. text-align: center;
  67. flex: 1.3;
  68. }
  69. header > span.iconfont.icon-category{
  70. font-size: 3rem;
  71. flex: 1;
  72. }
  73. header > span > a{
  74. color:white;
  75. text-align: center;
  76. }
  77. header > .search{
  78. display: flex;
  79. align-items: center;
  80. justify-content: space-around;
  81. }
  82. header > .search > span:first-child {
  83. color:red;
  84. font-size: 2rem;
  85. font-weight: bold;
  86. margin-right: 0.8rem;
  87. }
  88. header > .search > .iconfont.icon-search{
  89. font-size: 2.2rem;
  90. color:lightgrey;
  91. border-left: 1px solid #D3D3D3;
  92. padding: 0 .4rem;
  93. }
  94. header > .search > input{
  95. border: none;
  96. outline: none;
  97. height: 2.9rem;
  98. font-size: 1.6rem;
  99. flex: 3;
  100. color:#CCCCCC;
  101. }
  102. /* main主体样式 */
  103. @import url("resetCSS.css");
  104. main{
  105. display: flex;
  106. flex-flow: column nowrap;
  107. }
  108. main > div {
  109. height: 20rem;
  110. }
  111. main> div >.banner{
  112. background-color: #c72518;
  113. height: 10rem;
  114. text-align: center;
  115. border: none;
  116. border-bottom-right-radius:4rem;
  117. border-bottom-left-radius: 4rem;
  118. }
  119. main> div >.banner> img{
  120. height: 16rem;
  121. width: 90vw;
  122. border-radius: 1rem;
  123. }
  124. main > .slider{
  125. margin-top: 5rem ;
  126. width: 100vw;
  127. display: flex;
  128. justify-content: center;
  129. }
  130. main > .slider >img{
  131. width: 33.333%;
  132. }
  133. main > nav {
  134. width: 100vw;
  135. display: flex;
  136. flex-flow:row wrap;
  137. justify-content: space-evenly;
  138. }
  139. main > nav > div {
  140. width: 20vw;
  141. display: flex;
  142. flex-flow: column nowrap;
  143. align-items: center;
  144. column-rule: #999;
  145. }
  146. main > nav > div >img {
  147. width: 16vw;
  148. }
  149. main > .ms {
  150. margin-top: 1rem;
  151. display: flex;
  152. width: 100vw;
  153. justify-content: space-evenly;
  154. }
  155. main > .ms > div {
  156. display: flex;
  157. flex-flow: column nowrap;
  158. width: 22vw;
  159. height: 12rem;
  160. align-items: center;
  161. justify-content: space-around;
  162. color: white;
  163. font-size: 1em;
  164. background-color: #e6272f;
  165. border-radius: 1rem;
  166. }
  167. main > .ms >div > img{
  168. background-color: #fff;
  169. border-radius: 1rem;
  170. width: 18vw;
  171. }
  172. main > .ms >div > span:first-of-type{
  173. background-color: #69a69f;
  174. border-radius: 1rem;
  175. width: 18vw;
  176. font-size: 0.4em;
  177. height: 2rem;
  178. text-align: center;
  179. line-height: 2rem;
  180. position: relative;
  181. top:-2rem;
  182. }
  183. main > .ms > div > span:last-of-type{
  184. font-size: 1.4rem;
  185. margin-top:-2.4rem;
  186. }
  187. main > .shop {
  188. display: flex;
  189. flex-flow:column nowrap;
  190. align-items: center;
  191. }
  192. main > .shop > img {
  193. width: 90vw;
  194. margin-top:1rem;
  195. }
  196. main > .shop >.shop-detail {
  197. display: flex;
  198. flex-flow: row wrap;
  199. /* width: 100vw; */
  200. justify-content: space-evenly;
  201. }
  202. main > .shop >.shop-detail > div{
  203. display: flex;
  204. flex-flow: column nowrap;
  205. width: 46vw;
  206. margin-top: 1rem;
  207. }
  208. main >.shop > .shop-detail > div > img {
  209. /* background-color: red; */
  210. border-radius: 1rem;
  211. }
  212. main >.shop > .shop-detail > div > div{
  213. display: flex;
  214. justify-content: space-between;
  215. }
  216. main >.shop > .shop-detail > div > div >span:first-child{
  217. color:red;
  218. }
  219. main >.shop > .shop-detail > div > div >span:last-child{
  220. background-color: #969896;
  221. border-radius: 0.8rem;
  222. width: 4rem;
  223. text-align: center;
  224. }
  225. /* 底部样式 */
  226. @import url("resetCSS.css");
  227. footer{
  228. display: flex;
  229. justify-content: space-evenly;
  230. align-items: center;
  231. }
  232. footer>a>img{
  233. width: 7rem;
  234. }

1.3、运行结果

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