Blogger Information
Blog 18
fans 3
comment 3
visits 16233
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex PC端的一个布局方案 一个移动端的布局方案
刹那永恒个人博客
Original
922 people have browsed it

一.PC端布局方案

  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>PC端布局方案</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. a {
  14. text-decoration: none;
  15. color: #ccc;
  16. }
  17. body {
  18. display: flex;
  19. /* 垂直流不换行 */
  20. flex-flow: column nowrap;
  21. }
  22. .container {
  23. display: flex;
  24. min-height: 300px;
  25. margin: 10px auto;
  26. /* 居中对齐 */
  27. justify-content: center;
  28. }
  29. .container > aside,
  30. .container > main {
  31. padding: 10px;
  32. }
  33. .container > aside {
  34. flex: 0 0 200px;
  35. }
  36. .container > main {
  37. flex: 0 0 450px;
  38. margin: 0 10px;
  39. }
  40. header,
  41. footer {
  42. height: 50px;
  43. border: 1px dashed #000;
  44. }
  45. header {
  46. display: flex;
  47. /* 所有项目在交叉轴方向上垂直居中 */
  48. align-items: center;
  49. }
  50. header a {
  51. flex: 0 1 100px;
  52. text-align: center;
  53. }
  54. header a:first-of-type {
  55. margin-right: 50px;
  56. }
  57. header > a:last-of-type {
  58. margin-left: auto;
  59. }
  60. header a:hover:not(:first-of-type) {
  61. color: pink;
  62. }
  63. footer {
  64. text-align: center;
  65. }
  66. footer {
  67. display: flex;
  68. /* 主轴方向水平且不换行 */
  69. flex-flow: column nowrap;
  70. /* text-align: center; */
  71. }
  72. </style>
  73. </head>
  74. <body>
  75. <header>
  76. <a href="">logo</a>
  77. <a href="">首页</a>
  78. <a href="">栏目1</a>
  79. <a href="">栏目2</a>
  80. <a href="">栏目3</a>
  81. <a href="">登陆</a>
  82. </header>
  83. <div class="container">
  84. <aside>左边栏</aside>
  85. <main>主题内容区</main>
  86. <aside>右边栏</aside>
  87. </div>
  88. <footer>
  89. php中文网©版权所有 (2020-2030)|备案号:安-00001号
  90. <p><a href=""></a></p>
  91. <p>中国合肥 | 电话+86 -0551 88888888</p>
  92. </footer>
  93. </body>
  94. </html>


二.手机端flex布局

直接上代码

  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="./css/font-icon.css" />
  8. <link rel="stylesheet" href="./css/common.css" />
  9. <style>
  10. html{
  11. width: 100vw;
  12. height: 100vh;
  13. font-size: 14px;
  14. }
  15. body{
  16. display:flex;
  17. flex-flow: column wrap;
  18. background-color: #eeeeee;
  19. /* position: relative; */
  20. }
  21. /* --------------------菜单栏-------------------------- */
  22. header{
  23. /* 转为弹性布局 */
  24. display: flex;
  25. /* 水平不换行 */
  26. flex-flow: row nowrap;
  27. /* 背景色 */
  28. background-color: rgb(51, 51, 51);
  29. /* 宽高 */
  30. height: 32px;
  31. width: 100vw;
  32. /* 可放大 可收缩 尺寸自动 */
  33. flex-flow: 1 1 auto;
  34. /* 两端对齐 */
  35. justify-content: space-between;
  36. /* 上下居中 */
  37. align-items: center;
  38. /* 调整内边距 */
  39. padding:0 20px;
  40. position: fixed;
  41. }
  42. header>*{
  43. /* 设置大小和颜色 */
  44. font-size:1.2rem;
  45. color: #eee;
  46. }
  47. /* --------------------轮播图------------------------ */
  48. .banner{
  49. width: 100vw;
  50. }
  51. .banner>img{
  52. width: 100vw;
  53. }
  54. /* --------------商品主导航--------------------- */
  55. /* 主导航栏 nav >div >a >img p */
  56. nav{ */
  57. display:flex;
  58. /* 水平 自动换行 */
  59. flex-flow: row wrap;
  60. /* 宽度可视区100% */
  61. width: 100vw;
  62. /* 可放大 可收缩 尺寸自动 */
  63. flex: 1 1 auto;
  64. }
  65. nav>div{
  66. margin: 10px 0;
  67. display:flex;
  68. /* 水平自动换行 */
  69. flex-flow: row wrap;
  70. }
  71. nav>div>a{
  72. display: flex;
  73. width: 20vw;
  74. flex-flow: row wrap;
  75. flex: 1 1 auto;
  76. align-items: center;
  77. margin: 7px 0;
  78. }
  79. nav>div>a>img{
  80. width: 40%;
  81. /* height:auto; */
  82. }
  83. nav>div>a{
  84. display:flex;
  85. flex-flow:column nowrap;
  86. flex: 1 1 auto;
  87. }
  88. /* -------------热销商品大标题---------div>h1+span-------------------------- */
  89. .rxtitle{
  90. display: flex;
  91. flex:1 1 auto;
  92. align-items: center;
  93. color:rgb(252, 94, 94);
  94. /* width: 96vw; */
  95. /* margin: 0 50px; */
  96. margin: 10px 20px;
  97. }
  98. /* ----hoot-goods">hoot-goods-one-----------------热销商品------------------------------------ */
  99. .hoot-goods{
  100. width: 96vw;
  101. display:flex;
  102. flex-flow: row wrap;
  103. flex:1 1 auto;
  104. align-items: center;
  105. justify-content: center;
  106. margin: 10px auto;
  107. border-radius: 5px;
  108. /* position: relative; */
  109. }
  110. /* 图片和标题 */
  111. .hoot-goods-one{
  112. background-color: #fff;
  113. display: flex;
  114. flex-flow: column wrap;
  115. flex: 1 1 auto;
  116. width: 45vw;
  117. font-size: 0.7rem;
  118. margin: 2px;
  119. border-radius: 5px;
  120. }
  121. .hoot-goods-one:hover{
  122. color:chartreuse;
  123. }
  124. /* 购物车和价格 */
  125. .hoot-goods-jiage{
  126. display: flex;
  127. flex-flow: row wrap;
  128. justify-content: center;
  129. width: 50vw;
  130. color: red;
  131. }
  132. /* 商品图和名称 */
  133. .hoot-goods-one>a{
  134. width: 48vw;
  135. display: flex;
  136. flex-flow: column wrap;
  137. align-items: center;
  138. }
  139. /* 商品名 */
  140. .hoot-goods-one>a>p{
  141. padding: 3px 0;
  142. }
  143. /* 商品图 */
  144. .hoot-goods-one>a>img{
  145. width: 30vw;
  146. display: flex;
  147. flex: 1 1 auto;
  148. padding: 10px 0;
  149. }
  150. .list-title{
  151. /* background-color: rgb(116, 116, 116); */
  152. width: 100vw;
  153. height: 50px;
  154. text-align: center;
  155. line-height: 50px;
  156. }
  157. /* ---------------------------列表商品------------------ */
  158. .last-goods{
  159. display: flex;
  160. flex-flow: row wrap;
  161. flex-flow: 1 1 auto;
  162. width: 96vw;
  163. margin: 0 auto;
  164. /* align-content: center; */
  165. }
  166. .last-goods-one{
  167. display: flex;
  168. flex-flow: row wrap;
  169. flex-flow: 1 1 auto;
  170. width: 96vw;
  171. /* margin: 10 0; */
  172. background-color: #fff;
  173. align-content: center;
  174. border-radius: 3px;
  175. margin: 1px auto;
  176. }
  177. .last-goods-one>a{
  178. margin: 15px 0;
  179. display: flex;
  180. flex-flow: row wrap;
  181. flex: 1 1 auto;
  182. /* width: 100vw; */
  183. width: 40vw;
  184. text-align: center;
  185. align-items: center;
  186. justify-content: space-between;
  187. justify-content: center;
  188. justify-content: space-evenly;
  189. }
  190. .last-goods-one>a>*{
  191. width: 40vw;
  192. text-align: center;
  193. }
  194. /* ------------footer-------------------------- */
  195. footer{
  196. /* 转为flex */
  197. display: flex;
  198. flex-flow: row nowrap;
  199. flex: 1 1 auto;
  200. min-height: 30px;
  201. background-color: black;
  202. /* 居中 */
  203. justify-content: center;
  204. /* 分散对齐 */
  205. justify-content: space-evenly;
  206. align-items: center;
  207. }
  208. footer>*{
  209. color: #fff;
  210. }
  211. footer>a>*:hover{
  212. color: pink;
  213. }
  214. </style>
  215. </head>
  216. <body>
  217. <!-- headr -->
  218. <header>
  219. <a href="">logo</a>
  220. <span class="iconfont">&#xe61f;</span>
  221. </header>
  222. <!-- 轮播图 -->
  223. <div class="banner">
  224. <img src="./images/banner.jpg" alt="" />
  225. </div>
  226. <!-- 主导航 -->
  227. <nav>
  228. <div>
  229. <a href="">
  230. <img src="./images/chaoshi.png" alt="" />
  231. <p>京东超市</p>
  232. </a>
  233. <a href="">
  234. <img src="./images/shumadianqi.png" alt="" />
  235. <p>数码电器</p>
  236. </a>
  237. <a href="">
  238. <img src="./images/jingdongfushi.png" alt="" />
  239. <p>京东服饰</p>
  240. </a>
  241. <a href="">
  242. <img src="./images/jingdongshengxian.png" alt="" />
  243. <p>京东生鲜</p>
  244. </a>
  245. <a href="">
  246. <img src="./images/dongjia.png" alt="" />
  247. <p>京东到家</p>
  248. </a>
  249. <a href="">
  250. <img src="./images/chongzhijiaofei.png" alt="" />
  251. <p>充值缴费</p>
  252. </a>
  253. <a href="">
  254. <img src="./images/9.9yuanpin.png" alt="" />
  255. <p>9.9元拼</p>
  256. </a>
  257. <a href="">
  258. <img src="./images/lingquan.png" alt="" />
  259. <p>领券</p>
  260. </a>
  261. <a href="">
  262. <img src="./images/zhuanqian.png" alt="" />
  263. <p>赚钱</p>
  264. </a>
  265. <a href="">
  266. <img src="./images/plus.png" alt="" />
  267. <p>PLUS会员</p>
  268. </a>
  269. </nav>
  270. <!-- 热销商品 标题 --------------------------------------------------------------->
  271. <div class="rxtitle">
  272. <h1 class="rxsphead">热销商品&nbsp;
  273. </h1><span class="iconfont huo">&#xe60b;</span>
  274. </div>
  275. <!-- 热销商品大盒子 -------------------------------------------->
  276. <div class="hoot-goods">
  277. <!-- - 热销单个商品 -start-> -->
  278. <div class="hoot-goods-one">
  279. <a href="" >
  280. <img src="./images/goods1.jpg" alt="">
  281. <p>Apple iPhone 11 128G</p></a>
  282. <div class="hoot-goods-jiage">
  283. <!-- 价格购物车 -->
  284. <span>1888元</span>&nbsp;&nbsp;&nbsp;
  285. <span class="iconfont huo">&#xe602;</span>
  286. </div>
  287. </div>
  288. <!-- 热销单个end -->
  289. <!-- - 热销单个商品 -start-> -->
  290. <div class="hoot-goods-one">
  291. <a href="" >
  292. <img src="./images/goods2.jpg" alt="">
  293. <p>联想100核电脑</p></a>
  294. <div class="hoot-goods-jiage">
  295. <!-- 价格购物车 -->
  296. <span>1888元</span>&nbsp;&nbsp;&nbsp;
  297. <span class="iconfont huo">&#xe602;</span>
  298. </div>
  299. </div>
  300. <!-- 热销单个end -->
  301. <!-- - 热销单个商品 -start-> -->
  302. <div class="hoot-goods-one">
  303. <a href="" >
  304. <img src="./images/goods3.jpg" alt="">
  305. <p>滚筒洗衣机</p></a>
  306. <div class="hoot-goods-jiage">
  307. <!-- 价格购物车 -->
  308. <span>1888元</span>&nbsp;&nbsp;&nbsp;
  309. <span class="iconfont huo">&#xe602;</span>
  310. </div>
  311. </div>
  312. <!-- 热销单个end -->
  313. <!-- - 热销单个商品 -start-> -->
  314. <div class="hoot-goods-one">
  315. <a href="" >
  316. <img src="./images/goods4.jpg" alt="">
  317. <p>华为P80手机</p></a>
  318. <div class="hoot-goods-jiage">
  319. <!-- 价格购物车 -->
  320. <span>1888元</span>&nbsp;&nbsp;&nbsp;
  321. <span class="iconfont huo">&#xe602;</span>
  322. </div>
  323. </div>
  324. <!-- 热销单个end -->
  325. <!-- 热销单个end -->
  326. <!-- - 热销单个商品 -start-> -->
  327. <div class="hoot-goods-one">
  328. <a href="" >
  329. <img src="./images/goods5.png" alt="">
  330. <p>vivoX21 PLUS</p></a>
  331. <div class="hoot-goods-jiage">
  332. <!-- 价格购物车 -->
  333. <span>1888元</span>&nbsp;&nbsp;&nbsp;
  334. <span class="iconfont huo">&#xe602;</span>
  335. </div>
  336. </div>
  337. <!-- 热销单个end -->
  338. <!-- 热销单个end -->
  339. <!-- 热销单个end -->
  340. <!-- - 热销单个商品 -start-> -->
  341. <div class="hoot-goods-one">
  342. <a href="" >
  343. <img src="./images/goods6.webp" alt="">
  344. <p>罗西尼手表</p></a>
  345. <div class="hoot-goods-jiage">
  346. <!-- 价格购物车 -->
  347. <span>1888元</span>&nbsp;&nbsp;&nbsp;
  348. <span class="iconfont huo">&#xe602;</span>
  349. </div>
  350. </div>
  351. <!-- 热销单个end -->
  352. </div>
  353. <!-- 热销单个end -->
  354. <!-- ---------商品列表大标题------- -->
  355. <h2 class="list-title">商品列表<span class="iconfont hot" style="color: coral; font-size: 1.5rem;">&#xe64b;</span></h2>
  356. </body>
  357. </html>
  358. <!-- ---------------------------商品列表------------------------ -->
  359. <!-- start------------------------------------ -->
  360. <div class="last-goods">
  361. <div class="last-goods-one">
  362. <a href="">
  363. <img src="./images/goods6.webp" alt="">
  364. <p>罗西尼手表罗西尼手表罗尼手表罗西尼手表罗西尼手表罗西</p>
  365. </a>
  366. </div>
  367. <!-- end----------------------------------------- -->
  368. <!-- start------------------------------------ -->
  369. <div class="last-goods">
  370. <div class="last-goods-one">
  371. <a href="">
  372. <img src="./images/goods6.webp" alt="">
  373. <p>罗西尼手表罗西尼手表罗尼手表罗西尼手表罗西尼手表罗西</p>
  374. </a>
  375. </div>
  376. <!-- end----------------------------------------- -->
  377. <!-- start------------------------------------ -->
  378. <div class="last-goods">
  379. <div class="last-goods-one">
  380. <a href="">
  381. <img src="./images/goods6.webp" alt="">
  382. <p>罗西尼手表罗西尼手表罗尼手表罗西尼手表罗西尼手表罗西</p>
  383. </a>
  384. </div>
  385. <!-- end----------------------------------------- -->
  386. <!-- start------------------------------------ -->
  387. <div class="last-goods">
  388. <div class="last-goods-one">
  389. <a href="">
  390. <img src="./images/goods6.webp" alt="">
  391. <p>罗西尼手表罗西尼手表罗尼手表罗西尼手表罗西尼手表罗西</p>
  392. </a>
  393. </div>
  394. <!-- end----------------------------------------- -->
  395. <!-- start------------------------------------ -->
  396. <div class="last-goods">
  397. <div class="last-goods-one">
  398. <a href="">
  399. <img src="./images/goods6.webp" alt="">
  400. <p>罗西尼手表罗西尼手表罗尼手表罗西尼手表罗西尼手表罗西</p>
  401. </a>
  402. </div>
  403. <!-- end----------------------------------------- -->
  404. <!-- -----------------footer---------------------------- -->
  405. <footer>
  406. <a href="">
  407. <span class="iconfont hot">&#xe60c;首页</span>
  408. </a>
  409. <a href="">
  410. <span class="iconfont hot">&#xe64b;分类</span>
  411. </a>
  412. <a href="">
  413. <span class="iconfont hot">&#xe602;购物车</span>
  414. </a>
  415. <a href="">
  416. <span class="iconfont hot">&#xe65b;未登录</span>
  417. </a>
  418. </footer>
  419. </body>

实际效果

总结

  • 写代码之前想好框架结构很重要
  • 备注信息很重要 代码多了不容易乱,容易让思路清晰
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