博客列表 >《仿京东首页》20201223

《仿京东首页》20201223

杨凡的博客
杨凡的博客原创
2020年12月24日 18:07:27999浏览

html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  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/css/index.css">
  8. <link rel="stylesheet" href="static/font/jd/iconfont.css">
  9. <style>
  10. </style>
  11. </head>
  12. <body>
  13. <!-- 页眉 -->
  14. <div class="header">
  15. <!-- 字体图标菜单 -->
  16. <div class="menu iconfont icon-caidan"></div>
  17. <!-- 搜索框 -->
  18. <div class="search">
  19. <div class="logo">JD</div>
  20. <div class="zoom iconfont icon-fangdajing-copy "></div>
  21. <input type="text" name="" id="" class="words" value="电钢琴">
  22. </div>
  23. <!-- 登录按钮 -->
  24. <a href="" class="login">登录</a>
  25. <!--固定 -->
  26. <div class="dk">
  27. <div class="gg iconfont icon-gonggong-jingdong"></div>
  28. <a href="">打开APP</a>
  29. </div>
  30. </div>
  31. <!-- 主体 -->
  32. <div class="main">
  33. <div class="bg">
  34. <div class="bg_bc"></div>
  35. <img src="static/images/bg/bg.dpg" alt="">
  36. </div>
  37. <div class="bgtp">
  38. <img src="static/images/bg/bg1.dpg" alt="">
  39. <img src="static/images/bg/bg2.dpg" alt="">
  40. <img src="static/images/bg/bg3.dpg" alt="">
  41. </div>
  42. <!-- 导航区 -->
  43. <ul class="nav">
  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-2.png" alt=""></a>
  50. <a href="">数码电器</a>
  51. </li>
  52. <li>
  53. <a href=""><img src="static/images/dh/nav-3.png" alt=""></a>
  54. <a href="">京东服饰</a>
  55. </li>
  56. <li>
  57. <a href=""><img src="static/images/dh/nav-4.png" alt=""></a>
  58. <a href="">京东生鲜</a>
  59. </li>
  60. <li>
  61. <a href=""><img src="static/images/dh/nav-5.png" alt=""></a>
  62. <a href="">京东到家</a>
  63. </li>
  64. <li>
  65. <a href=""><img src="static/images/dh/nav-6.png" alt=""></a>
  66. <a href="">充值缴费</a>
  67. </li>
  68. <li>
  69. <a href=""><img src="static/images/dh/nav-7.png" alt=""></a>
  70. <a href="">9.9元拼</a>
  71. </li>
  72. <li>
  73. <a href=""><img src="static/images/dh/nav-8.png" alt=""></a>
  74. <a href="">领劵</a>
  75. </li>
  76. <li>
  77. <a href=""><img src="static/images/dh/nav-9.png" alt=""></a>
  78. <a href="">借钱</a>
  79. </li>
  80. <li>
  81. <a href=""><img src="static/images/dh/nav-10.png" alt=""></a>
  82. <a href="">PLUS会员</a>
  83. </li>
  84. </ul>
  85. <!-- 秒杀区 -->
  86. <div class="ms">
  87. <!-- 头部 -->
  88. <div class="ms-top">
  89. <div class="left">
  90. <div class="title">京东秒杀</div>
  91. <div class="notice">
  92. <div class="tips">10
  93. <img src="static/images/ms/点场.png" alt="">
  94. </div>
  95. <div class="time"><span>00</span>:<span>15</span>:<span>22</span></div>
  96. </div>
  97. </div>
  98. <div class="right">更多秒杀</div>
  99. </div>
  100. <!-- 主体 -->
  101. <ul class="ms-body">
  102. <li class="item">
  103. <a href=""><img src="static/images/ms/1.dpg" alt=""></a>
  104. <div class="iconfont icon-icon-test">338</div>
  105. <div class="iconfont icon-icon-test">558</div>
  106. </li>
  107. <li class="item">
  108. <a href=""><img src="static/images/ms/2.dpg" alt=""></a>
  109. <div class="iconfont icon-icon-test">1859</div>
  110. <div class="iconfont icon-icon-test">2499</div>
  111. </li>
  112. <li class="item">
  113. <a href=""><img src="static/images/ms/3.dpg" alt=""></a>
  114. <div class="iconfont icon-icon-test">4769</div>
  115. <div class="iconfont icon-icon-test">5699</div>
  116. </li>
  117. <li class="item">
  118. <a href=""><img src="static/images/ms/4.dpg" alt=""></a>
  119. <div class="iconfont icon-icon-test">1818</div>
  120. <div class="iconfont icon-icon-test">2199</div>
  121. </li>
  122. <li class="item">
  123. <a href=""><img src="static/images/ms/5.dpg" alt=""></a>
  124. <div class="iconfont icon-icon-test">1399</div>
  125. <div class="iconfont icon-icon-test">1799</div>
  126. </li>
  127. <li class="item">
  128. <a href=""><img src="static/images/ms/6.dpg" alt=""></a>
  129. <div class="iconfont icon-icon-test">20969</div>
  130. <div class="iconfont icon-icon-test">22199</div>
  131. </li>
  132. </ul>
  133. </div>
  134. <!-- 推荐区猜你喜欢 -->
  135. <div class="cnxh">
  136. <img src="static/images/sp/cnxh.png" alt="">
  137. </div>
  138. <ul class="tj">
  139. <li class="item">
  140. <a href=""><img src="static/images/sp/1.webp" alt=""></a>
  141. <p>玉兰油(OLAY)美白润肤面霜50g乳液女士护肤品补水保湿提亮肤色粉嫩白皙改善暗黄美白修护</p>
  142. <div class="price">
  143. <div class="jg iconfont icon-icon-test">59</div>
  144. <div class="mj">满减</div>
  145. <div class="kxs">看相似</div>
  146. </div>
  147. </li>
  148. <li class="item">
  149. <a href=""><img src="static/images/sp/2.webp" alt=""></a>
  150. <p>HR赫莲娜活颜修护舒缓霜 50ml(白绷带 质地面霜 保湿 改善细纹)圣诞节礼物</p>
  151. <div class="price">
  152. <div class="jg iconfont icon-icon-test">3180</div>
  153. <div class="mj">闪购</div>
  154. <div class="kxs">看相似</div>
  155. </div>
  156. </li>
  157. <li class="item">
  158. <a href=""><img src="static/images/sp/3.webp" alt=""></a>
  159. <p>玉兰油(OLAY)锁水布丁水凝霜50g面霜乳液女士护肤品补水保湿提亮肤色淡化细纹水嫩滋润白皙透亮</p>
  160. <div class="price">
  161. <div class="jg iconfont icon-icon-test">199</div>
  162. <div class="mj">满减</div>
  163. <div class="kxs">看相似</div>
  164. </div>
  165. </li>
  166. <li class="item">
  167. <a href=""><img src="static/images/sp/4.webp" alt=""></a>
  168. <p>适用笔记本电脑包手提公文男女12Air13Pro15.6内胆16商务14寸 深空灰 14/15寸</p>
  169. <div class="price">
  170. <div class="jg iconfont icon-icon-test">59</div>
  171. <div class="kxs">看相似</div>
  172. </div>
  173. </li>
  174. <li class="item">
  175. <a href=""><img src="static/images/sp/5.webp" alt=""></a>
  176. <p>//img11.360buyimg.com/jdphoto/s102x28_jfs/t14512/288/2659278877/2368/8468a10d/5aadf9daNd4909ddc.png</p>
  177. <div class="price">
  178. <div class="jg iconfont icon-icon-test">138</div>
  179. <div class="kxs">看相似</div>
  180. </div>
  181. </li>
  182. <li class="item">
  183. <a href=""><img src="static/images/sp/6.webp" alt=""></a>
  184. <p>超媛加绒加厚半高领打底衫女2020新款秋装气质小衫长袖T恤显瘦内搭T血BH-350-B#656#你 棕色 S</p>
  185. <div class="price">
  186. <div class="jg iconfont icon-icon-test">104</div>
  187. <div class="mj">满减</div>
  188. <div class="kxs">看相似</div>
  189. </div>
  190. </li>
  191. </ul>
  192. </div>
  193. <!-- 页脚 -->
  194. <div class="footer">
  195. <a href="">
  196. <div class="iconfont icon-jingdong2"></div>
  197. <span>首页</span>
  198. </a>
  199. <a href="">
  200. <div class="iconfont icon-classification"></div>
  201. <span>分类</span>
  202. </a>
  203. <a href="">
  204. <div class="iconfont icon-jingdongwujiemiandanjiekoupeizhi-01"></div>
  205. <span>京喜</span>
  206. </a>
  207. <a href="">
  208. <div class="iconfont icon-gouwuche1 "></div>
  209. <span>购物车</span>
  210. </a>
  211. <a href="">
  212. <div class="iconfont icon-yonghu"></div>
  213. <span>未登录</span>
  214. </a>
  215. </div>
  216. </body>
  217. </html>

CSS代码

页面样式

  1. /* 导入公共初始化样式表 */
  2. @import 'reset.css';
  3. /* 页眉 */
  4. .header{
  5. background-color: #e43130;
  6. color: white;
  7. height: 4.4rem;
  8. /* 固定定位 */
  9. position: fixed;
  10. top: 0;
  11. left: 0;
  12. right: 0;
  13. /* 设置层级 */
  14. z-index: 100;
  15. font-size: 1.4rem;
  16. }
  17. /* 页脚 */
  18. .footer{
  19. background-color: #fafafa;
  20. color: #666;
  21. height: 4.4rem;
  22. /* 边框阴影效果 */
  23. box-shadow: 0 0 3px #999;
  24. /* 固定定位 */
  25. position: fixed;
  26. bottom: 0;
  27. left: 0;
  28. right: 0;
  29. font-size: 1.4rem;
  30. }
  31. /* 主体 */
  32. .main{
  33. /* 绝对定位 */
  34. position: absolute;
  35. top: 4.4rem;
  36. bottom: 4.4rem;
  37. left: 0;
  38. right: 0;
  39. font-size: 1.4rem;
  40. }
  41. /* header样式 */
  42. .header{
  43. /* 设置为flex布局 */
  44. display: flex;
  45. /* 垂直居中 */
  46. align-items: center;
  47. }
  48. /* 页眉三部分比例1:6:1 */
  49. .header .login{
  50. color: #fff;
  51. text-align: center;
  52. flex: 1;
  53. }
  54. .header .menu{
  55. text-align: center;
  56. font-size: 3rem;
  57. flex: 1;
  58. }
  59. .header .search{
  60. flex:6;
  61. padding: 0.5rem;
  62. background-color: #fff;
  63. border-radius: 3rem;
  64. display: flex;
  65. }
  66. /* logo */
  67. .header .search .logo{
  68. color: #e43130;
  69. flex: 0 1 4rem;
  70. font-size: 2rem;
  71. /* 水平垂直居中 */
  72. text-align: center;
  73. line-height: 2rem;
  74. }
  75. /* 放大镜 */
  76. .header .search .zoom{
  77. color: #ccc;
  78. flex: 0 1 4rem;
  79. font-size: 2rem;
  80. border-left: 1px solid;
  81. /* 水平垂直居中 */
  82. text-align: center;
  83. line-height: 2rem;
  84. }
  85. /* 搜索文本框 */
  86. .header .search .words{
  87. flex: auto;
  88. /* 去边框 */
  89. border: none;
  90. /* 去轮廓线 */
  91. outline: none;
  92. color: #aaa;
  93. }
  94. /* 固定定位打开APP f32607 */
  95. .header .dk{
  96. background-color: #f32607;
  97. position: fixed;
  98. top: 7rem;
  99. right: 0;
  100. border-radius: 1rem 0 0 1rem;
  101. display: flex;
  102. }
  103. .header .dk .gg{
  104. font-size: 3rem;
  105. }
  106. .header .dk a{
  107. color: #fff;
  108. padding: 0.5rem 1rem 0 0.5rem;
  109. }
  110. /* 固定定位打开APP */
  111. /* header样式 */
  112. .main{
  113. display: flex;
  114. flex-flow: column nowrap;
  115. }
  116. /* 轮播 */
  117. .main .bg{
  118. display: flex;
  119. flex-flow: column nowrap;
  120. background-color: #fff;
  121. position: relative;
  122. height: 15rem;
  123. }
  124. .main .bg .bg_bc{
  125. background-color: #C82519;
  126. border-radius: 0 0 4rem 4em;
  127. height: 10rem;
  128. margin-bottom: 10rem;
  129. }
  130. .main .bg img{
  131. width: 90%;
  132. position: absolute;
  133. top:1rem;
  134. left: 2rem;
  135. right: 2rem;
  136. margin: auto;
  137. border-radius: 1rem;
  138. }
  139. .main .bgtp{
  140. background-color: #fff;
  141. display: flex;
  142. }
  143. .main .bgtp img{
  144. width: 33%;
  145. }
  146. /* 轮播 */
  147. /* 导航区 */
  148. .main .nav{
  149. padding: 1rem;
  150. display: flex;
  151. flex-flow: row wrap;
  152. /* 两端对其 */
  153. justify-content: space-between;
  154. }
  155. .main .nav img{
  156. height: 4rem;
  157. width: 4rem;
  158. }
  159. .main .nav li{
  160. flex: 1 1 20%;
  161. display: flex;
  162. flex-flow: column nowrap;
  163. align-items: center;
  164. margin: 1rem 0;
  165. }
  166. /* 导航区 */
  167. /* 秒杀区 */
  168. /* 头部 */
  169. .main .ms{
  170. background-color: #fff;
  171. padding: 1rem;
  172. margin: 1rem 0;
  173. margin: 0 1rem;
  174. border-radius: 2rem;
  175. }
  176. .main .ms .ms-top{
  177. font-size: 1.3rem;
  178. height: 3rem;
  179. display: flex;
  180. /* 两端对其 */
  181. justify-content: space-between;
  182. }
  183. .main .ms .ms-top .left{
  184. display: flex;
  185. }
  186. .main .ms .ms-top .left .notice{
  187. font-size: 1.1rem;
  188. height: 2rem;
  189. border-radius: 2rem;
  190. margin-left: 1rem;
  191. display: flex;
  192. /* 水平垂直居中 */
  193. justify-content: center;
  194. align-items: center;
  195. }
  196. .main .ms .ms-top .left .notice .tips{
  197. font-size: 1.5rem;
  198. color: #e43130;
  199. padding: 0 0.5rem;
  200. }
  201. .main .ms .ms-top .left .notice .tips img{
  202. width: 2rem;
  203. height: 1.7rem;
  204. }
  205. .main .ms .ms-top .left .time{
  206. font-size: 1.5rem;
  207. color: #e43130;
  208. padding: 0 0.5rem;
  209. }
  210. .main .ms .ms-top .left .time span{
  211. background-color: #e43130;
  212. color: #fff;
  213. border-radius: 0.3rem;
  214. }
  215. .main .ms .ms-top .right{
  216. color: #e43130;
  217. }
  218. /* 主体 */
  219. .main .ms .ms-body{
  220. display: flex;
  221. justify-content: space-between;
  222. }
  223. .main .ms .ms-body img{
  224. height: 5.5rem;
  225. width: 5.5rem;
  226. }
  227. .main .ms .ms-body .item div:first-of-type{
  228. color: #f2270c;
  229. font-size: 1.3rem;
  230. }
  231. .main .ms .ms-body .item div:last-of-type{
  232. color: #999;
  233. font-size: 1.3rem;
  234. text-decoration: line-through;
  235. }
  236. /* 秒杀区 */
  237. /* 推荐区猜你喜欢 */
  238. .main .cnxh img{
  239. width: 100%;
  240. }
  241. .main .tj{
  242. display: flex;
  243. font-size: 1.3rem;
  244. flex-wrap: wrap;
  245. }
  246. .main .tj .item{
  247. flex: 1 1 46%;
  248. background-color: #fff;
  249. overflow: hidden;
  250. display: flex;
  251. flex-flow: column nowrap;
  252. border-radius: 1rem;
  253. padding: 1rem;
  254. position: relative;
  255. }
  256. .main .tj .item p{
  257. overflow: hidden;
  258. text-overflow:ellipsis;
  259. white-space: nowrap;
  260. }
  261. .main .tj .item .price{
  262. display: flex;
  263. }
  264. .main .tj .item .price .jg{
  265. color: #fa2c19;
  266. font-size: 1.6rem;
  267. }
  268. .main .tj .item .price .mj{
  269. margin-left: 1rem;
  270. border: 1px solid #fa2c19;
  271. border-radius: 0.2rem;
  272. font-size: 1.3rem;
  273. margin-top: 0.3rem;
  274. }
  275. .main .tj .item .price .kxs{
  276. position: absolute;
  277. right: 0;
  278. background-color: #f0f2f5;
  279. color: grey;
  280. margin-top: 0.5rem;
  281. border-radius: 1rem 0 0 1rem;
  282. }
  283. .main .tj .item:nth-of-type(odd){
  284. margin: 0.5rem 0.5rem 0.5rem 1rem;
  285. }
  286. .main .tj .item:nth-of-type(even){
  287. margin: 0.5rem 0.5rem 0.5rem 1rem;
  288. }
  289. .main .tj .item img{
  290. width: 100%;
  291. height: 100%;
  292. }
  293. /* 推荐区猜你喜欢 */
  294. /* 菜单栏 */
  295. .footer{
  296. display: flex;
  297. justify-content: space-around;
  298. align-items: center;
  299. }
  300. .footer a{
  301. display: flex;
  302. flex-flow: column nowrap;
  303. align-items: center;
  304. }
  305. .footer a .iconfont{
  306. font-size: 2rem;
  307. }
  308. .footer a span{
  309. font-size: 1rem;
  310. }
  311. /* 菜单栏 */

公共样式

  1. *{
  2. /* 清理外边距 */
  3. margin: 0;
  4. /* 清理内边距 */
  5. padding: 0;
  6. /* 设置ie盒子 */
  7. box-sizing: border-box;
  8. }
  9. li{
  10. /* 去除小黑点 */
  11. list-style: none;
  12. }
  13. a{
  14. /* 文本颜色 */
  15. color: #7b7b7b;
  16. /* 去掉下划线 */
  17. text-decoration: none;
  18. }
  19. body{
  20. /* 页面背景颜色 */
  21. background-color: #F6F6F6;
  22. }
  23. html{
  24. /* 页面字号 */
  25. font-size: 10px;
  26. }
  27. /* 媒体查询 */
  28. @media screen and (min-width:320px){
  29. html{
  30. /* 页面字号 */
  31. font-size: 8px;
  32. }
  33. }
  34. @media screen and (min-width:375px){
  35. html{
  36. /* 页面字号 */
  37. font-size: 10px;
  38. }
  39. }
  40. @media screen and (min-width:480px){
  41. html{
  42. /* 页面字号 */
  43. font-size: 12px;
  44. }
  45. }
  46. @media screen and (min-width:640px){
  47. html{
  48. /* 页面字号 */
  49. font-size: 14px;
  50. }
  51. }
  52. @media screen and (min-width:720px){
  53. html{
  54. /* 页面字号 */
  55. font-size: 16px;
  56. }
  57. }
  58. @media screen and (min-width:960px){
  59. html{
  60. /* 页面字号 */
  61. font-size: 18px;
  62. }
  63. }
  64. @media screen and (min-width:1024px){
  65. html{
  66. /* 页面字号 */
  67. font-size: 20px;
  68. }
  69. }

总结:
代码中穿插众多flex布局属性及定位知识,通过此案例对前面的知识进行了巩固。

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