Blogger Information
Blog 22
fans 1
comment 1
visits 22283
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用flex布局,模仿m.php.cn首页----PHP培训十期线上班
Miss灬懒虫
Original
672 people have browsed it

使用flex布局,模仿m.php.cn首页(补12.27)

效果图

目录结构

布局分析

首先将页面分割为三部分,headermainfooter,其中header、和footer是固定的,而main则是自适应高度。

HTML代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>移动端页面布局</title>
  6. <link rel="stylesheet" href="css/index.css">
  7. </head>
  8. <body>
  9. <!--页面头部-->
  10. <div class="page-header">
  11. <a href=""><img src="image/login.png" alt=""></a>
  12. <a href=""><img src="image/logo.png" alt=""></a>
  13. <a href=""><i class="iconfont">&#xec6b;</i></a>
  14. </div>
  15. <div class="page-main">
  16. <!--头部banner滚动图-->
  17. <div class="banner">
  18. <a href=""><img src="image/banner/banner1.jpg" alt=""></a>
  19. </div>
  20. <!--页面头部导航-->
  21. <div class="nav">
  22. <a class="nav-list" href="">
  23. <img src="image/navs/html.png" alt="">
  24. <span>HTML/css</span>
  25. </a>
  26. <a class="nav-list" href="">
  27. <img src="image/navs/JavaScript.png" alt="">
  28. <span>JavaScript</span>
  29. </a>
  30. <a class="nav-list" href="">
  31. <img src="image/navs/code.png" alt="">
  32. <span>服务端</span>
  33. </a>
  34. <a class="nav-list" href="">
  35. <img src="image/navs/sql.png" alt="">
  36. <span>数据库</span>
  37. </a>
  38. <a class="nav-list" href="">
  39. <img src="image/navs/app.png" alt="">
  40. <span>移动端</span>
  41. </a>
  42. <a class="nav-list" href="">
  43. <img src="image/navs/manual.png" alt="">
  44. <span>手册</span>
  45. </a>
  46. <a class="nav-list" href="">
  47. <img src="image/navs/tool2.png" alt="">
  48. <span>工具</span>
  49. </a>
  50. <a class="nav-list" href="">
  51. <img src="image/navs/live.png" alt="">
  52. <span>直播</span>
  53. </a>
  54. </div>
  55. <!--推荐课程-->
  56. <div class="recommend">
  57. <h3>推荐课程</h3>
  58. <div class="rec-top">
  59. <a href=""><img src="image/1.jpg" alt=""></a>
  60. <a href=""><img src="image/2.jpg" alt=""></a>
  61. </div>
  62. <div class="rec-list">
  63. <a href=""><img src="image/3.jpg" alt=""></a>
  64. <div class="rec-content">
  65. <h2><a href="">CI框架30分钟极速入门</a></h2>
  66. <p>
  67. <span class="level">中级</span>
  68. <span>55724次播放</span>
  69. </p>
  70. </div>
  71. </div>
  72. <div class="rec-list">
  73. <a href=""><img src="image/4.jpg" alt=""></a>
  74. <div class="rec-content">
  75. <h2><a href="">2018前端入门_HTML5</a></h2>
  76. <p>
  77. <span class="level">初级</span>
  78. <span>257725次播放</span>
  79. </p>
  80. </div>
  81. </div>
  82. </div>
  83. <!--最新更新-->
  84. <div class="update">
  85. <h3>最新更新</h3>
  86. <div class="update-list">
  87. <a href=""><img src="image/2-1.jpg" alt=""></a>
  88. <div class="update-content">
  89. <h2><a href="">2019python自学视频</a></h2>
  90. <span>本课程适合想从零开始学习 Python 编程语言的开发</span>
  91. <div class="update-level">
  92. <span class="level">中级</span>
  93. <span>55724次播放</span>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="update-list">
  98. <a href=""><img src="image/2-2.png" alt=""></a>
  99. <div class="update-content">
  100. <h2><a href="">2019python自学视频</a></h2>
  101. <span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
  102. <div class="update-level">
  103. <span class="level">中级</span>
  104. <span>55724次播放</span>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="update-list">
  109. <a href=""><img src="image/2-3.jpg" alt=""></a>
  110. <div class="update-content">
  111. <h2><a href="">2019python自学视频</a></h2>
  112. <span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
  113. <div class="update-level">
  114. <span class="level">中级</span>
  115. <span>55724次播放</span>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="update-list">
  120. <a href=""><img src="image/2-4.png" alt=""></a>
  121. <div class="update-content">
  122. <h2><a href="">2019python自学视频</a></h2>
  123. <span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
  124. <div class="update-level">
  125. <span class="level">中级</span>
  126. <span>55724次播放</span>
  127. </div>
  128. </div>
  129. </div>
  130. <div class="update-list">
  131. <a href=""><img src="image/2-5.jpg" alt=""></a>
  132. <div class="update-content">
  133. <h2><a href="">2019python自学视频</a></h2>
  134. <span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
  135. <div class="update-level">
  136. <span class="level">中级</span>
  137. <span>55724次播放</span>
  138. </div>
  139. </div>
  140. </div>
  141. <div class="update-list">
  142. <a href=""><img src="image/2-6.png" alt=""></a>
  143. <div class="update-content">
  144. <h2><a href="">2019python自学视频</a></h2>
  145. <span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你进入python</span>
  146. <div class="update-level">
  147. <span class="level">中级</span>
  148. <span>55724次播放</span>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <!--最新文章-->
  154. <div class="docs">
  155. <h3>最新文章</h3>
  156. <div class="doc-list">
  157. <div class="doc-content">
  158. <a href=""><h2>VSCode,控制台乱码设置</h2></a>
  159. <a href="">发布时间:2019-12-30</a>
  160. </div>
  161. <a href="image/doc/vscode.jpg"><img src="image/doc/vscode.jpg" alt=""></a>
  162. </div>
  163. <div class="doc-list">
  164. <div class="doc-content">
  165. <a href=""><h2>VSCode,控制台乱码设置</h2></a>
  166. <a href="">发布时间2019-12-30</a>
  167. </div>
  168. <a href=""><img src="image/doc/facebookcrsf.jpg" alt=""></a>
  169. </div>
  170. <div class="doc-list">
  171. <div class="doc-content">
  172. <a href=""><h2>VSCode,控制台乱码设置</h2></a>
  173. <a href="">发布时间2019-12-30</a>
  174. </div>
  175. <a href=""><img src="image/doc/yii.jpg" alt=""></a>
  176. </div>
  177. <div class="doc-list">
  178. <div class="doc-content">
  179. <a href=""><h2>VSCode,控制台乱码设置</h2></a>
  180. <a href="">发布时间2019-12-30</a>
  181. </div>
  182. <a href=""><img src="image/doc/facebookxss.jpg" alt=""></a>
  183. </div>
  184. <div class="doc-list">
  185. <div class="doc-content">
  186. <a href=""><h2>VSCode,控制台乱码设置</h2></a>
  187. <a href="">发布时间2019-12-30</a>
  188. </div>
  189. <a href=""><img src="image/doc/yii.jpg" alt=""></a>
  190. </div>
  191. <a class="a-more" href="">更多内容</a>
  192. </div>
  193. <!--最新博文-->
  194. <div class="blog-articles">
  195. <h3>最新博文</h3>
  196. <div class="com-articles">
  197. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  198. <a href="">2019-12-27</a>
  199. </div>
  200. <div class="com-articles">
  201. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  202. <a href="">2019-12-27</a>
  203. </div>
  204. <div class="com-articles">
  205. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  206. <a href="">2019-12-27</a>
  207. </div>
  208. <div class="com-articles">
  209. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  210. <a href="">2019-12-27</a>
  211. </div>
  212. <a class="a-more" href="">更多内容</a>
  213. </div>
  214. <!--最新问答-->
  215. <div class="questions">
  216. <h3>最新问答</h3>
  217. <div class="com-articles">
  218. <span>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</span>
  219. <span>2019-12-27</span>
  220. </div>
  221. <div class="com-articles">
  222. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  223. <a href="">2019-12-27</a>
  224. </div>
  225. <div class="com-articles">
  226. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  227. <a href="">2019-12-27</a>
  228. </div>
  229. <div class="com-articles">
  230. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  231. <a href="">2019-12-27</a>
  232. </div>
  233. <div class="com-articles">
  234. <a href=""><h2>composer安装laravel,Nginx服务器路配置解决404问题,创建简单的控制</h2></a>
  235. <a href="">2019-12-27</a>
  236. </div>
  237. <a class="a-more" href="">更多内容</a>
  238. </div>
  239. </div>
  240. <!--页面底部导航-->
  241. <div class="page-footer">
  242. <a href=""><i class="iconfont">&#xe605;</i>首页</a>
  243. <a href=""><i class="iconfont">&#xec61;</i>视频</a>
  244. <a href=""><i class="iconfont">&#xeb66;</i>社区</a>
  245. <a href=""><i class="iconfont">&#xe60e;</i>我的</a>
  246. </div>
  247. </body>
  248. </html>

CSS代码

  1. /*引入字体图标库*/
  2. @font-face {
  3. font-family: 'iconfont';
  4. src: url('../../html/1220/css/font/iconfont.eot');
  5. src: url('../../html/1220/css/font/iconfont.eot?#iefix') format('embedded-opentype'),
  6. url('../../html/1220/css/font/iconfont.woff2') format('woff2'),
  7. url('../../html/1220/css/font/iconfont.woff') format('woff'),
  8. url('../../html/1220/css/font/iconfont.ttf') format('truetype'),
  9. url('../../html/1220/css/font/iconfont.svg#iconfont') format('svg');
  10. }
  11. .iconfont {
  12. font-family: "iconfont", serif !important;
  13. font-size: 16px;
  14. font-style: normal;
  15. -webkit-font-smoothing: antialiased;
  16. -moz-osx-font-smoothing: grayscale;
  17. }
  18. /*初始化 --公共样式*/
  19. *{
  20. margin: 0;
  21. padding: 0;
  22. /* outline: 1px dashed red;*/
  23. }
  24. a{
  25. color: #888888;
  26. text-decoration: none;
  27. }
  28. a:hover{
  29. cursor: pointer;
  30. }
  31. h2{
  32. font-weight: normal;
  33. }
  34. h3{
  35. font-size: 18px;
  36. }
  37. /*页面整体样式*/
  38. body{
  39. width: 100vw;
  40. height: 100vh;
  41. max-width: 768px;
  42. font-size: 13px;
  43. color: #888888;
  44. background-color: #edeff0;
  45. box-sizing: border-box;
  46. display: flex;
  47. flex-flow: column nowrap;
  48. margin: 0 auto;
  49. }
  50. /*#8e888e -图标原色/图标红色#ff0000 /级别背景色 #595757*/
  51. /*页头页尾与主体内容布局样式*/
  52. body >.page-header,body >.page-main,body >.page-footer{
  53. width: 100%;
  54. max-width: 768px;
  55. min-width: 320px;
  56. }
  57. /*页面头部 header*/
  58. body >.page-header{
  59. height: 42px;
  60. background-color: #2d353c;
  61. display: flex;
  62. justify-content:space-between;
  63. }
  64. body >.page-header > a:first-of-type >img {
  65. width: 25px;
  66. height: 25px;
  67. border: 1px solid #8F9498;
  68. border-radius: 50px;
  69. margin: 8px 8px;
  70. }
  71. body >.page-header > a:nth-child(2) >img{
  72. height: 42px;
  73. }
  74. body >.page-header > a:last-of-type{
  75. line-height: 42px;
  76. text-align: right;
  77. margin-right: 14px;
  78. }
  79. body >.page-header >a>i{
  80. font-size: 20px;
  81. color: #fff;
  82. }
  83. /*页面主体内容 main*/
  84. body >.page-main{
  85. width: 100%;
  86. flex: auto;
  87. overflow: auto;
  88. display: flex;
  89. flex-flow: column nowrap;
  90. }
  91. /*banner图 样式*/
  92. body >.page-main >.banner{
  93. height: 150px;
  94. }
  95. .banner >a{
  96. width: 100%;
  97. height: 150Px;
  98. display: inline-block;
  99. }
  100. .banner >a >img{
  101. width: 100%;
  102. height: 150Px;
  103. }
  104. /*顶部导航区 样式*/
  105. body >.page-main >.nav{
  106. background-color: #fff;
  107. margin-top: 10px;
  108. display: flex;
  109. flex-flow: row wrap;
  110. justify-content: space-between;
  111. }
  112. .nav-list{
  113. width: 160px;
  114. height: 75px;
  115. display: flex;
  116. flex-flow: column nowrap;
  117. justify-content: center;
  118. align-items: center;
  119. margin-top: 10px;
  120. }
  121. .nav-list> img{
  122. width: 45px;
  123. height: 45px;
  124. }
  125. .nav-list> span{
  126. font-weight: bolder;
  127. }
  128. /*推荐课程*/
  129. body>.page-main>.recommend{
  130. height: 400px;
  131. margin: 20px 10px 0 10px;
  132. display: flex;
  133. flex-flow: column nowrap;
  134. }
  135. .recommend>.rec-top{
  136. margin: 10px 0;
  137. display: flex;
  138. flex-flow: row nowrap;
  139. justify-content: space-between;
  140. }
  141. .recommend>.rec-top> a{
  142. width: 367px;
  143. height: 90px;
  144. line-height: 90px;
  145. }
  146. .recommend>.rec-top> a> img{
  147. width: 367px;
  148. height: 90px;
  149. }
  150. .recommend >.rec-list{
  151. height: 100px;
  152. margin: 10px 0;
  153. padding: 10px 10px;
  154. background-color: #fff;
  155. display: flex;
  156. flex-flow: row nowrap;
  157. }
  158. .recommend >.rec-list >a,.recommend >.rec-list>.rec-content{
  159. width: 295px;
  160. height: 80px;
  161. margin: auto;
  162. }
  163. .recommend >.rec-list >a>img{
  164. width: 295px;
  165. height: 80px;
  166. }
  167. .recommend >.rec-list>.rec-content{
  168. margin-left: 10px;
  169. flex: auto;
  170. }
  171. .recommend >.rec-list>.rec-content >p{
  172. height: 20px;
  173. line-height: 20px;
  174. margin-top: 10px;
  175. }
  176. .recommend >.rec-list>.rec-content >p >span:first-of-type{
  177. width: 40px;
  178. height: 20px;
  179. line-height: 20px;
  180. background-color:#595757;
  181. font-size: 12px;
  182. color: #fff;
  183. text-align: center;
  184. border-radius: 5px;
  185. margin-right: 5px;
  186. display: inline-block;
  187. }
  188. /*最新更新*/
  189. body>.page-main>.update{
  190. display: flex;
  191. flex-flow: column nowrap;
  192. margin: 20px 10px 0 10px;
  193. }
  194. .update>.update-list{
  195. background-color: #fff;
  196. margin-top: 10px;
  197. padding: 10px 10px;
  198. display: flex;
  199. flex-flow: row nowrap;
  200. }
  201. .update>.update-list>a{
  202. width: 295px;
  203. height: 80px;
  204. }
  205. .update>.update-list>a >img{
  206. width: 295px;
  207. height: 80px;
  208. }
  209. .update>.update-list>.update-content{
  210. height: 80px;
  211. margin-left: 10px;
  212. flex: auto;
  213. display: flex;
  214. flex-flow: column nowrap;
  215. justify-content: space-between;
  216. }
  217. .update>.update-list>.update-content>.update-level{
  218. display: flex;
  219. flex-flow: row nowrap;
  220. justify-content: space-between;
  221. }
  222. .update>.update-list>.update-content>.update-level>.level{
  223. width: 40px;
  224. height: 20px;
  225. line-height: 20px;
  226. background-color:#595757;
  227. font-size: 12px;
  228. color: #fff;
  229. text-align: center;
  230. border-radius: 5px;
  231. margin-right: 5px;
  232. display: inline-block;
  233. }
  234. /*最新文章*/
  235. body>.page-main>.docs{
  236. display: flex;
  237. flex-flow: column nowrap;
  238. margin: 20px 10px 0 10px;
  239. }
  240. .docs>.doc-list{
  241. height: 65px;
  242. background-color: #fff;
  243. margin: 10px 0;
  244. padding: 10px 10px;
  245. display: flex;
  246. flex-flow: row nowrap;
  247. }
  248. .docs>.doc-list>a{
  249. width: 218px;
  250. height: 65px;
  251. }
  252. .docs>.doc-list>a>img{
  253. width: 218px;
  254. height: 65px;
  255. }
  256. .docs>.doc-list>.doc-content{
  257. flex: auto;
  258. display: flex;
  259. flex-flow: column nowrap;
  260. }
  261. .docs>.doc-list>.doc-content>a:last-of-type{
  262. margin-top: 10px;
  263. }
  264. .docs>.doc-list>.doc-content>a>h2,.com-articles>a>h2{
  265. font-size: 14px;
  266. font-weight: bold;
  267. white-space: nowrap;
  268. }
  269. /*最新博文*/
  270. body>.page-main>.blog-articles{
  271. margin: 20px 10px 0 10px;
  272. display: flex;
  273. flex-flow: column nowrap;
  274. }
  275. .com-articles{
  276. height: 30px;
  277. line-height: 30px;
  278. background-color: #fff;
  279. margin: 10px 0;
  280. padding: 10px 10px;
  281. display: flex;
  282. flex-flow: row nowrap;
  283. justify-content: space-between;
  284. }
  285. .a-more{
  286. height: 30px;
  287. background-color: #fff;
  288. line-height: 30px;
  289. text-align: center;
  290. }
  291. /*最新问答*/
  292. body>.page-main>.questions{
  293. margin: 20px 10px 0 10px;
  294. display: flex;
  295. flex-flow: column nowrap;
  296. }
  297. /*页面尾部导航 footer*/
  298. body >.page-footer{
  299. height: 60px;
  300. background-color: #eeeeee;
  301. display: flex;
  302. justify-content:space-around ;
  303. }
  304. body>.page-footer>a{
  305. height: 60px;
  306. font-size: 1.1rem;
  307. line-height: 60px;
  308. text-align: center;
  309. }
  310. body>.page-footer>a:nth-child(1){
  311. color: #ff2017;
  312. }
  313. body>.page-footer>a:nth-child(1)>i{
  314. color: #ff2017;
  315. }
  316. body>.page-footer>a>i{
  317. font-size: 24px;
  318. }
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