Blogger Information
Blog 100
fans 8
comment 2
visits 150193
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex实现PC端通用布局方案与移动端主页布局(高仿小米商城app主页静态)
lilove的博客
Original
1411 people have browsed it

PC端通用布局案例:

  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>小刚日志:pc端通用布局方案</title>
  7. </head>
  8. <style>
  9. /* 初始化所有元素 */
  10. * {
  11. padding: 0;
  12. margin: 0;
  13. box-sizing: border-box;
  14. }
  15. /* 将body转为弹性盒子,使页面结构垂直布局 */
  16. body {
  17. min-width: 800px;
  18. display: flex;
  19. flex-flow: column nowrap;
  20. }
  21. /* 头部也转为弹性盒子 */
  22. header {
  23. width: 100%;
  24. height: 50px;
  25. padding: 0 20px;
  26. background-color: dimgrey;
  27. display: flex;
  28. }
  29. /* 导航条中的链接样式初始化 */
  30. header > a {
  31. padding: 0 15px;
  32. line-height: 50px;
  33. color: honeydew;
  34. text-decoration: none;
  35. }
  36. /* 将导航条第一个链接(一般是logo图片)单独设置右外边距使之与其他导航分开 */
  37. header > a:first-of-type {
  38. margin-right: 100px;
  39. }
  40. /* 将注册和登录链接单独分开(后两个a标签) */
  41. header > a:nth-last-of-type(2) {
  42. margin-left: auto;
  43. }
  44. /* 将导航条中除了第一个a标签外的所有标签设置样式 */
  45. header > a:hover:not(:first-of-type) {
  46. color: teal;
  47. background-color: khaki;
  48. cursor: pointer;
  49. }
  50. /* 主体部分容器设置成弹性盒子 */
  51. .container {
  52. min-width: 700px;
  53. min-height: 600px;
  54. margin: 10px auto;
  55. display: flex;
  56. justify-content: center;
  57. }
  58. /* 设置主体各区域内容内边距 */
  59. .container > aside,
  60. .container > main {
  61. padding: 10px;
  62. }
  63. /* 设置主体区域左右边栏样式 */
  64. .container > aside {
  65. width: 150px;
  66. border: 1px solid black;
  67. }
  68. /* 设置主体区域主题内容样式 */
  69. .container > main {
  70. width: 400px;
  71. margin: 0 10px;
  72. border: 1px dashed black;
  73. }
  74. /* 页面底部样式 */
  75. footer {
  76. display: flex;
  77. flex-flow: column nowrap;
  78. text-align: center;
  79. border: 1px solid black;
  80. }
  81. </style>
  82. <body>
  83. <header>
  84. <a href="#">logo</a>
  85. <a href="">首页</a>
  86. <a href="">工具</a>
  87. <a href="">手册</a>
  88. <a href="">登录</a>
  89. <a href="">注册</a>
  90. </header>
  91. <div class="container">
  92. <aside class="left">左边</aside>
  93. <main class="main">主体</main>
  94. <aside class="right">右边</aside>
  95. </div>
  96. <footer>
  97. <p>XXXX©备案号:<a href="#">000000022222</a></p>
  98. <p>版权所有|翻版必究</p>
  99. </footer>
  100. </body>
  101. </html>

运行效果:


移动端主页布局(高仿小米商城app主页)

  • 几乎100%用flex布局实现小米商城app主页静态内容,由于代码较多,将css样式写到了外部文件中。

  • demo.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. <link rel="stylesheet" href="demo.css" />
  7. <title>小刚日志:移动端主页布局(仿小米商城APP首页)</title>
  8. </head>
  9. <style>
  10. /* unicode方式引入阿里字体图标 */
  11. @font-face {
  12. font-family: "iconfont";
  13. src: url("font_icon/iconfont.eot");
  14. src: url("font_icon/iconfont.eot?#iefix") format("embedded-opentype"),
  15. url("font_icon/iconfont.woff2") format("woff2"),
  16. url("font_icon/iconfont.woff") format("woff"),
  17. url("font_icon/iconfont.ttf") format("truetype"),
  18. url("font_icon/iconfont.svg#iconfont") format("svg");
  19. }
  20. /* 设置字体图标样式 */
  21. .iconfont {
  22. font-family: "iconfont" !important;
  23. font-size: 30px;
  24. font-style: normal;
  25. -webkit-font-smoothing: antialiased;
  26. -webkit-text-stroke-width: 0.2px;
  27. -moz-osx-font-smoothing: grayscale;
  28. }
  29. .fontsmall {
  30. font-size: 17px;
  31. }
  32. </style>
  33. <body>
  34. <!-- 搜索条 -->
  35. <header>
  36. <nav>
  37. <a href="#"><strong>99包邮</strong></a>
  38. <div>
  39. <a href="#"><span class="iconfont fontsmall"></span></a>
  40. <input type="text" placeholder="输入搜索" />
  41. <a href="#"><span class="iconfont fontsmall"></span></a>
  42. </div>
  43. <a href="#"><span class="iconfont"></span></a>
  44. <a href="#"><span class="iconfont"></span></a>
  45. </nav>
  46. </header>
  47. <!-- 主体部分 -->
  48. <div class="container">
  49. <!-- 轮播图 -->
  50. <div class="carousel">
  51. <a href="#"><img src="images/banner1.png" alt="1" /></a>
  52. </div>
  53. <!-- 分类 -->
  54. <div class="classify">
  55. <div class="classifyShop">
  56. <div>
  57. <a href="#">
  58. <img src="images/classify.png" alt="" />
  59. <p>分类</p>
  60. </a>
  61. </div>
  62. <div>
  63. <a href="#">
  64. <img src="images/classify.png" alt="" />
  65. <p>分类</p>
  66. </a>
  67. </div>
  68. <div>
  69. <a href="#">
  70. <img src="images/classify.png" alt="" />
  71. <p>分类</p>
  72. </a>
  73. </div>
  74. <div>
  75. <a href="#">
  76. <img src="images/classify.png" alt="" />
  77. <p>分类</p>
  78. </a>
  79. </div>
  80. <div>
  81. <a href="#">
  82. <img src="images/classify.png" alt="" />
  83. <p>分类</p>
  84. </a>
  85. </div>
  86. <div>
  87. <a href="#">
  88. <img src="images/classify.png" alt="" />
  89. <p>分类</p>
  90. </a>
  91. </div>
  92. <div>
  93. <a href="#">
  94. <img src="images/classify.png" alt="" />
  95. <p>分类</p>
  96. </a>
  97. </div>
  98. <div>
  99. <a href="#">
  100. <img src="images/classify.png" alt="" />
  101. <p>分类</p>
  102. </a>
  103. </div>
  104. <div>
  105. <a href="#">
  106. <img src="images/classify.png" alt="" />
  107. <p>分类</p>
  108. </a>
  109. </div>
  110. <div>
  111. <a href="#">
  112. <img src="images/classify.png" alt="" />
  113. <p>分类</p>
  114. </a>
  115. </div>
  116. </div>
  117. <div class="want">
  118. <div>
  119. <p>想要标题</p>
  120. <p>4百人想要</p>
  121. </div>
  122. <a href="#"><img src="images/want.png" alt="" /></a>
  123. <div>
  124. <p>想要标题</p>
  125. <p>2千人想要</p>
  126. </div>
  127. <a href="#"><img src="images/want.png" alt="" /></a>
  128. <div>
  129. <p>想要标题</p>
  130. <p>2千人想要</p>
  131. </div>
  132. <a href="#"><img src="images/want.png" alt="" /></a>
  133. </div>
  134. </div>
  135. <!-- 广告图 -->
  136. <div class="advert">
  137. <a href="#"><img src="images/advert.png" alt="" /></a>
  138. </div>
  139. <!-- 推荐商品 -->
  140. <div class="hotGoods">
  141. <div>
  142. <a href="#"><img src="images/hot.png" alt="" /></a>
  143. <p>优惠价格:222元</p>
  144. <p>商品名</p>
  145. </div>
  146. <div>
  147. <a href="#"><img src="images/hot.png" alt="" /></a>
  148. <p>优惠价格:222元</p>
  149. <p>商品名</p>
  150. </div>
  151. <div>
  152. <a href="#"><img src="images/hot.png" alt="" /></a>
  153. <p>优惠价格:222元</p>
  154. <p>商品名</p>
  155. </div>
  156. </div>
  157. <!-- 推荐活动 -->
  158. <div class="activity">
  159. <div>
  160. <a href="#">
  161. <h3>通讯福利专场</h3>
  162. <p>最高得168元话费</p>
  163. </a>
  164. <div>
  165. <a href="#"><img src="images/activity.png" alt="" /></a>
  166. <a href="#"><img src="images/activity.png" alt="" /></a>
  167. </div>
  168. </div>
  169. <div>
  170. <a href="#">
  171. <h3>正在直播<small>Live</small></h3>
  172. <p>小米端午节直播</p>
  173. </a>
  174. <div>
  175. <a href="#"><img src="images/activity.png" alt="" /></a>
  176. <a href="#"><img src="images/activity.png" alt="" /></a>
  177. </div>
  178. </div>
  179. <div>
  180. <a href="#">
  181. <h3>49元换电池</h3>
  182. <p>一场与鄂黑津的未完之约</p>
  183. </a>
  184. <div>
  185. <a href="#"><img src="images/activity.png" alt="" /></a>
  186. <a href="#"><img src="images/activity.png" alt="" /></a>
  187. </div>
  188. </div>
  189. <div>
  190. <a href="#">
  191. <h3>“粽享快乐”</h3>
  192. <p>最高立省800元</p>
  193. </a>
  194. <div>
  195. <a href="#"><img src="images/activity.png" alt="" /></a>
  196. <a href="#"><img src="images/activity.png" alt="" /></a>
  197. </div>
  198. </div>
  199. </div>
  200. <!-- 实时活动 -->
  201. <div class="actual">
  202. <!-- 秒杀 -->
  203. <div class="seckill">
  204. <div>
  205. <a href="#"><strong>小米秒杀</strong></a>
  206. <a href="#">
  207. <span>14点场</span>
  208. <span>00:13:51</span>
  209. </a>
  210. </div>
  211. <a href="#">
  212. <img src="images/seckill.png" alt="" />
  213. <p>¥99</p>
  214. <small><del>¥149</del></small>
  215. </a>
  216. <a href="#">
  217. <img src="images/seckill.png" alt="" />
  218. <p>¥1699</p>
  219. <small><del>¥2499</del></small>
  220. </a>
  221. <a href="#">
  222. <img src="images/seckill.png" alt="" />
  223. <p>¥579</p>
  224. <small><del>¥699</del></small>
  225. </a>
  226. </div>
  227. <!-- 新品 -->
  228. <div class="news">
  229. <a href="#">
  230. <strong>新品发布</strong><span>Redmi 10X ></span>
  231. </a>
  232. <a href="#">小米手环5 NFC版</a>
  233. <a href=""><img src="images/news.png" alt="" /></a>
  234. <a href=""><img src="images/news.png" alt="" /></a>
  235. </div>
  236. <!-- 项目 -->
  237. <div class="projects">
  238. <a href="#">
  239. <h3>小米众筹</h3>
  240. <p>科技新生活</p>
  241. <img src="images/projects.png" alt="" />
  242. </a>
  243. <a href="#">
  244. <h3>1分拼团</h3>
  245. <p>全场包邮</p>
  246. <img src="images/projects.png" alt="" />
  247. </a>
  248. <a href="#">
  249. <h3>以旧换新</h3>
  250. <p>便捷换新</p>
  251. <img src="images/projects.png" alt="" />
  252. </a>
  253. <a href="#">
  254. <h3>数码电器</h3>
  255. <p>科技生活</p>
  256. <img src="images/projects.png" alt="" />
  257. </a>
  258. </div>
  259. <div class="channel">
  260. <h3>精选频道</h3>
  261. <div>
  262. <div>
  263. <img src="images/channel.png" alt="" />
  264. <p>星球农场</p>
  265. </div>
  266. <div>
  267. <img src="images/channel.png" alt="" />
  268. <p>生活周边</p>
  269. </div>
  270. <div>
  271. <img src="images/channel.png" alt="" />
  272. <p>空调选购</p>
  273. </div>
  274. <div>
  275. <img src="images/channel.png" alt="" />
  276. <p>爆款新品</p>
  277. </div>
  278. <div>
  279. <img src="images/channel.png" alt="" />
  280. <p>企业团购</p>
  281. </div>
  282. </div>
  283. </div>
  284. <!-- 早报 -->
  285. <div class="newspaper">
  286. <a href="#">
  287. <strong>早报 </strong>
  288. <span>热门</span>
  289. 新品Redmi9,低至799起
  290. </a>
  291. <a href="#">更多</a>
  292. </div>
  293. </div>
  294. <!-- 公式条 -->
  295. <a href="#" class="standard">小米商城合规公示</a>
  296. <!-- 分类横条 -->
  297. <div class="category">
  298. <a href="#">
  299. <h4>精选</h4>
  300. <small>为你推荐</small>
  301. </a>
  302. <a href="#">
  303. <h4>手机</h4>
  304. <small>探索黑科技</small>
  305. </a>
  306. <a href="#">
  307. <h4>电器</h4>
  308. <small>数码家电</small>
  309. </a>
  310. <a href="#">
  311. <h4>特惠</h4>
  312. <small>多买多省</small>
  313. </a>
  314. <a href="#">
  315. <h4>智能家庭</h4>
  316. <small>生活听我的</small>
  317. </a>
  318. </div>
  319. <!-- 商品 -->
  320. <div class="goods">
  321. <a href="#">
  322. <img src="images/goods1.png" alt="" />
  323. <h5>商品标签商品标签商品标签商品标签商品标签商品标签</h5>
  324. <p><span>¥9999</span><span href="#">看相似</span></p>
  325. <span>简介</span>
  326. </a>
  327. <a href="#">
  328. <img src="images/goods2.png" alt="" />
  329. <h5>商品标签商品标签商品标签</h5>
  330. <p><span>¥899</span><span href="#">看相似</span></p>
  331. </a>
  332. <a href="#">
  333. <img src="images/goods3.png" alt="" />
  334. <h5>商品标签商品标签</h5>
  335. <p><span>¥899</span><span href="#">看相似</span></p>
  336. <span>简介</span>
  337. </a>
  338. <a href="#">
  339. <img src="images/goods2.png" alt="" />
  340. <h5>商品标签</h5>
  341. <p><span>¥99</span><span href="#">看相似</span></p>
  342. <span>简介</span>
  343. </a>
  344. <a href="#">
  345. <img src="images/goods3.png" alt="" />
  346. <h5>商品标签商品标签商品标签商品标签</h5>
  347. <p><span>¥79</span><span href="#">看相似</span></p>
  348. <span>简介</span>
  349. </a>
  350. <a href="#">
  351. <img src="images/goods1.png" alt="" />
  352. <h5>商品标签</h5>
  353. <p><span>¥899</span><span href="#">看相似</span></p>
  354. <span>简介</span>
  355. </a>
  356. <a href="#">
  357. <img src="images/goods2.png" alt="" />
  358. <h5>商品标签</h5>
  359. <p><span>¥899</span><span href="#">看相似</span></p>
  360. <span>简介</span>
  361. </a>
  362. <a href="#">
  363. <img src="images/goods3.png" alt="" />
  364. <h5>商品标签</h5>
  365. <p><span>¥899</span><span href="#">看相似</span></p>
  366. <span>简介</span>
  367. </a>
  368. <a href="#">
  369. <img src="images/goods2.png" alt="" />
  370. <h5>商品标签</h5>
  371. <p><span>¥899</span><span href="#">看相似</span></p>
  372. <span>简介</span>
  373. </a>
  374. <a href="#">
  375. <img src="images/goods1.png" alt="" />
  376. <h5>商品标签</h5>
  377. <p><span>¥899</span><span href="#">看相似</span></p>
  378. <span>简介</span>
  379. </a>
  380. </div>
  381. </div>
  382. <!-- 底部固定工具条 -->
  383. <footer>
  384. <a href="#">
  385. <span class="iconfont"></span>
  386. <p>首页</p>
  387. </a>
  388. <a href="#">
  389. <span class="iconfont"></span>
  390. <p>分类</p>
  391. </a>
  392. <a href="#">
  393. <span class="iconfont"></span>
  394. <p>星球</p>
  395. </a>
  396. <a href="#">
  397. <span class="iconfont"></span>
  398. <p>购物车</p>
  399. </a>
  400. <a href="#">
  401. <span class="iconfont"></span>
  402. <p>我的</p>
  403. </a>
  404. </footer>
  405. <!-- 回到顶部 -->
  406. <a href="#" class="backtop">回到顶部</a>
  407. </body>
  408. </html>
  • demo.css内容:
  1. /* 仿小米商城APP首页样式表 */
  2. /* 初始化 */
  3. * {
  4. padding: 0;
  5. margin: 0;
  6. box-sizing: border-box;
  7. }
  8. body {
  9. background-color: #f7f7f9;
  10. display: flex;
  11. flex-flow: column nowrap;
  12. padding: 50px 0 60px 0;
  13. }
  14. a {
  15. color: #737373;
  16. text-decoration: none;
  17. }
  18. /* 顶部工具条 */
  19. header {
  20. width: 100vw;
  21. background-color: #db2613;
  22. position: fixed;
  23. top: 0;
  24. left: 0;
  25. }
  26. header > nav {
  27. height: 50px;
  28. display: flex;
  29. justify-content: space-around;
  30. align-items: center;
  31. }
  32. header > nav > div {
  33. height: 30px;
  34. display: flex;
  35. }
  36. header > nav > div > input {
  37. width: 150px;
  38. height: 30px;
  39. border: 0;
  40. padding-left: 10px;
  41. }
  42. header > nav > div > :nth-child(odd) {
  43. color: #c6c8c7;
  44. background-color: #fff;
  45. }
  46. header > nav > div > :nth-child(1) {
  47. border-radius: 15px 0 0 15px;
  48. line-height: 30px;
  49. padding-left: 5px;
  50. }
  51. header > nav > div > :nth-child(3) {
  52. border-radius: 0 15px 15px 0;
  53. line-height: 30px;
  54. padding-right: 5px;
  55. }
  56. header > nav a {
  57. color: #f8eade;
  58. }
  59. /* 主体内容 */
  60. .container {
  61. width: 100%;
  62. display: flex;
  63. flex-direction: column;
  64. justify-content: center;
  65. }
  66. .container > * {
  67. margin: 10px auto 0 auto;
  68. }
  69. /* 轮播图 */
  70. .container > .carousel > a > img {
  71. width: 350px;
  72. }
  73. /* 分类 */
  74. .container > .classify {
  75. width: 90%;
  76. border-radius: 10px;
  77. background-color: #fff;
  78. }
  79. .container > .classify > .classifyShop {
  80. display: flex;
  81. flex-flow: row wrap;
  82. align-content: space-evenly;
  83. }
  84. .container > .classify > .classifyShop > div {
  85. margin: 0 auto;
  86. text-align: center;
  87. }
  88. .container > .classify > .classifyShop > div > a {
  89. color: #111;
  90. }
  91. .container > .classify > .classifyShop > div > a > img {
  92. width: 45px;
  93. margin: 10px 10px 0 10px;
  94. }
  95. .container > .classify > .want {
  96. display: flex;
  97. justify-content: center;
  98. align-items: center;
  99. }
  100. .container > .classify > .want > div {
  101. margin: 5px;
  102. font-size: 0.8rem;
  103. }
  104. .container > .classify > .want img {
  105. width: 30px;
  106. height: 30px;
  107. margin: auto 5px;
  108. }
  109. /* 广告图片 */
  110. .container > .advert > a > img {
  111. width: 100%;
  112. }
  113. .container > .hotGoods {
  114. width: 330px;
  115. display: flex;
  116. justify-content: space-evenly;
  117. text-align: center;
  118. }
  119. /* 推荐商品 */
  120. .container > .hotGoods > div {
  121. padding: 5px;
  122. border-radius: 10px;
  123. background-color: #0cd9c7;
  124. }
  125. .container > .hotGoods img {
  126. width: 90px;
  127. }
  128. .container > .hotGoods p {
  129. font-size: 0.7rem;
  130. color: #fff;
  131. }
  132. /* 推荐活动 */
  133. .container > .activity {
  134. width: 350px;
  135. border-radius: 10px;
  136. background-color: #fff;
  137. display: flex;
  138. flex-wrap: wrap;
  139. align-content: center;
  140. }
  141. .container > .activity > div {
  142. margin: auto 5px;
  143. }
  144. .container > .activity > div > a > h3 {
  145. color: black;
  146. }
  147. .container > .activity > div:nth-child(2) > a > h3 > small {
  148. font-size: xx-small;
  149. color: #fff;
  150. background-color: #fec435;
  151. border-radius: 0 5px;
  152. padding: 2px 5px;
  153. margin-left: 10px;
  154. text-align: right;
  155. }
  156. .container > .activity > div > a > p {
  157. font-size: 0.9rem;
  158. color: #fcc432;
  159. }
  160. .container > .activity img {
  161. width: 80px;
  162. }
  163. /* 实时活动 */
  164. .container > .actual {
  165. width: 350px;
  166. text-align: center;
  167. background-color: #fff;
  168. border-radius: 10px;
  169. display: flex;
  170. flex-flow: row wrap;
  171. align-content: space-around;
  172. }
  173. .container > .actual > .seckill,
  174. .container > .actual > .news {
  175. width: 170px;
  176. margin: auto;
  177. display: flex;
  178. flex-flow: row wrap;
  179. align-content: space-evenly;
  180. justify-content: space-evenly;
  181. }
  182. /* 秒杀 */
  183. .container > .actual > .seckill > div {
  184. height: 40px;
  185. display: flex;
  186. }
  187. .container > .actual > .seckill > div > a:first-of-type {
  188. width: 70px;
  189. color: black;
  190. line-height: 30px;
  191. margin-top: 5px;
  192. margin-bottom: 5px;
  193. }
  194. .container > .actual > .seckill > div > a:not(:first-of-type) {
  195. font-size: 10px;
  196. height: 18px;
  197. border: 1px solid #fa3726;
  198. border-radius: 16px;
  199. color: #fa3726;
  200. margin-top: 11px;
  201. margin-bottom: 11px;
  202. display: flex;
  203. }
  204. .container > .actual > .seckill > div > a:last-of-type > span:first-child {
  205. color: #fff;
  206. background-color: #fa3726;
  207. border-radius: 15px;
  208. }
  209. .container > .actual > .seckill img {
  210. width: 50px;
  211. }
  212. /* 新品 */
  213. .container > .actual > .news img {
  214. width: 80px;
  215. }
  216. .container > .actual > .news > a:first-child > strong {
  217. color: #111;
  218. margin-right: 5px;
  219. }
  220. .container > .actual > .news > a:first-child > span {
  221. background-color: #f3f3f3;
  222. border-radius: 15px;
  223. font-size: 11px;
  224. padding: 1px 3px;
  225. }
  226. .container > .actual > .news > a:first-child {
  227. margin: 5px auto 0 6px;
  228. }
  229. .container > .actual > .news > a:nth-child(2) {
  230. color: #e11e26;
  231. font-size: 12px;
  232. margin: 5px auto 10px 6px;
  233. }
  234. .container > .actual > .projects,
  235. .container > .actual > .channel,
  236. .container > .actual > .newspaper {
  237. width: 100%;
  238. display: flex;
  239. margin: 15px auto 0 auto;
  240. }
  241. /* 项目 */
  242. .container > .actual > .projects {
  243. justify-content: space-evenly;
  244. text-align: left;
  245. }
  246. .container > .actual > .projects > a > h3 {
  247. color: #111;
  248. }
  249. .container > .actual > .projects > a > p {
  250. color: #f4a688;
  251. margin-bottom: 5px;
  252. }
  253. .container > .actual > .projects > a > img {
  254. width: 80px;
  255. }
  256. /* 精选频道 */
  257. .container > .actual > .channel {
  258. flex-flow: column nowrap;
  259. }
  260. .container > .actual > .channel > h3 {
  261. text-align: left;
  262. padding: 5px 10px;
  263. }
  264. .container > .actual > .channel p {
  265. color: #a2a2a2;
  266. font-size: small;
  267. }
  268. .container > .actual > .channel > div {
  269. display: flex;
  270. justify-content: space-evenly;
  271. }
  272. .container > .actual > .channel > div > div {
  273. display: flex;
  274. flex-flow: column nowrap;
  275. align-items: center;
  276. }
  277. .container > .actual > .channel > div > div > img {
  278. width: 60px;
  279. }
  280. /* 早报 */
  281. .container > .actual > .newspaper {
  282. width: 100%;
  283. padding: 0 10px;
  284. margin-bottom: 10px;
  285. display: flex;
  286. }
  287. .container > .actual > .newspaper > a:first-child > span {
  288. color: #e49687;
  289. background-color: #ffe8df;
  290. text-align: center;
  291. padding: 2px;
  292. border-radius: 3px;
  293. font-size: xx-small;
  294. }
  295. .container > .actual > .newspaper > a:last-child {
  296. margin-left: auto;
  297. }
  298. /* 合规公示 */
  299. .container > .standard {
  300. width: 350px;
  301. color: #dcdedd;
  302. background-color: #fff;
  303. border-radius: 5px;
  304. padding: 5px;
  305. font-size: smaller;
  306. }
  307. /* 分类横条 */
  308. .container > .category {
  309. width: 360px;
  310. display: flex;
  311. align-content: center;
  312. justify-content: space-evenly;
  313. text-align: center;
  314. }
  315. .container > .category > a {
  316. width: 70px;
  317. }
  318. .container > .category > a > h4 {
  319. color: #fe6438;
  320. }
  321. .container > .category > a > small {
  322. color: #fff;
  323. font-size: x-small;
  324. background-color: #fe6438;
  325. border-radius: 15px;
  326. padding: 2px 3px;
  327. }
  328. /* 商品 */
  329. .container > .goods {
  330. width: 350px;
  331. display: flex;
  332. flex-flow: row wrap;
  333. justify-content: space-evenly;
  334. align-items: start;
  335. }
  336. .container > .goods > a {
  337. width: 160px;
  338. background-color: #fff;
  339. border-radius: 10px;
  340. padding: 5px;
  341. margin-top: 10px;
  342. display: flex;
  343. flex-flow: column wrap;
  344. }
  345. .container > .goods > a > * {
  346. margin-bottom: 5px;
  347. }
  348. .container > .goods > a > p {
  349. display: flex;
  350. }
  351. .container > .goods > a > p > span:first-of-type {
  352. color: #ea7c59;
  353. }
  354. .container > .goods > a > p > span:last-of-type {
  355. color: #8e938c;
  356. margin-left: auto;
  357. border: 1px solid #8e938c;
  358. border-radius: 15px;
  359. font-size: x-small;
  360. padding: 3px;
  361. }
  362. .container > .goods > a > span:last-child {
  363. color: #8e938c;
  364. border: 1px solid #8e938c;
  365. border-radius: 10px;
  366. font-size: xx-small;
  367. padding: 5px;
  368. }
  369. .container > .goods img {
  370. width: 150px;
  371. }
  372. /* 底部 */
  373. footer {
  374. /* 要底部固定须设置宽度 */
  375. width: 100vw;
  376. height: 60px;
  377. background-color: #fff;
  378. display: flex;
  379. /* 底部固定定位 */
  380. position: fixed;
  381. bottom: 0;
  382. }
  383. footer > a {
  384. width: 20%;
  385. height: 60px;
  386. color: #7c7c7c;
  387. display: flex;
  388. flex-flow: column wrap;
  389. text-align: center;
  390. }
  391. /* 回到顶部 */
  392. .backtop {
  393. width: 45px;
  394. height: 45px;
  395. color: white;
  396. text-align: center;
  397. background-color: #ff6a31;
  398. position: fixed;
  399. right: 10px;
  400. bottom: 80px;
  401. }

运行效果图:

动画演示:


总结:

这次案例将近期所学知识进行了汇总,遇到不少卡壳的地方,不过总算完成了。

  1. 在flex对齐方式上要清楚逻辑;
  2. 图标位置移动;
  3. 文字与图片的混排;
  4. 页头,页尾的固定;
  5. flex的嵌套使用;
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:第一步先把功能实现了, 优化是熟悉之后的事
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post