博客列表 >《Flex实战PHP中文网手机端首页布局》2019-12-27作业笔记

《Flex实战PHP中文网手机端首页布局》2019-12-27作业笔记

杨凡的博客
杨凡的博客原创
2020年02月04日 17:15:52641浏览

参考老师讲解后进行作业完善

HTML代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>PHP中文网移动端首页</title>
  6. <link rel="stylesheet" href="static/css/style.css">
  7. <link rel="stylesheet" href="static/font/iconfont.css">
  8. </head>
  9. <body>
  10. <!-- 顶部 -->
  11. <header>
  12. <img src="static/images/user_avatar.jpg" alt="">
  13. <img src="static/images/logo.png" alt="">
  14. <img src="static/images/user-nav.jpg" alt="">
  15. </header>
  16. <!-- 轮播图 -->
  17. <div class="banner">
  18. <img src="static/images/3.jpg" alt="">
  19. </div>
  20. <!-- 导航区 -->
  21. <nav>
  22. <ul>
  23. <li>
  24. <a href="#">
  25. <img src="static/images/html.png" alt="">
  26. <span>HTML/CSS</span>
  27. </a>
  28. </li>
  29. <li>
  30. <a href="#">
  31. <img src="static/images/JavaScript.png" alt="">
  32. <span>JavaScript</span>
  33. </a>
  34. </li>
  35. <li>
  36. <a href="#">
  37. <img src="static/images/code.png" alt="">
  38. <span>服务端</span>
  39. </a>
  40. </li>
  41. <li>
  42. <a href="#">
  43. <img src="static/images/sql.png" alt="">
  44. <span>数据库</span>
  45. </a>
  46. </li>
  47. </ul>
  48. <ul>
  49. <li>
  50. <a href="#">
  51. <img src="static/images/app.png" alt="">
  52. <span>移动端</span>
  53. </a>
  54. </li>
  55. <li>
  56. <a href="#">
  57. <img src="static/images/manual.png" alt="">
  58. <span>手册</span>
  59. </a>
  60. </li>
  61. <li>
  62. <a href="#">
  63. <img src="static/images/tool2.png" alt="">
  64. <span>工具</span>
  65. </a>
  66. </li>
  67. <li>
  68. <a href="#">
  69. <img src="static/images/live.png" alt="">
  70. <span>直播</span>
  71. </a>
  72. </li>
  73. </ul>
  74. </nav>
  75. <!-- 推荐课程 -->
  76. <main>
  77. <article class="recommend">
  78. <h3>推荐课程</h3>
  79. <section>
  80. <a href="#"><img src="static/images/01.jpg" alt=""></a>
  81. <a href="#"><img src="static/images/02.jpg" alt=""></a>
  82. </section>
  83. <section>
  84. <div>
  85. <a href="#"><img src="static/images/tjkc3.jpg" alt=""></a>
  86. <span>
  87. <a href="#">CI框架30分钟极速入门</a>
  88. <span><i>中级</i>57521次播放</span>
  89. </span>
  90. </div>
  91. <div>
  92. <a href="#"><img src="static/images/tjkc4.jpg" alt=""></a>
  93. <span>
  94. <a href="#">2018前端入门_HTML5</a>
  95. <span><i>初级</i>271038次播放</span>
  96. </span>
  97. </div>
  98. </section>
  99. </article>
  100. <article class="recommend_new">
  101. <h3>最新更新</h3>
  102. <section>
  103. <div>
  104. <a href="#"><img src="static/images/1.png" alt=""></a>
  105. <span>
  106. <a href="#">PHP快速操控Excel之PhpSpreadsheet</a>
  107. <p>老的PHPExcel已经停止更新了!目前最新的是使用phpOffice插件PhpSpr...</p>
  108. <span><i>中级</i>5492次播放</span>
  109. </span>
  110. </div>
  111. </section>
  112. <section>
  113. <div>
  114. <a href="#"><img src="static/images/2.png" alt=""></a>
  115. <span>
  116. <a href="#">Thinkphp6.0正式版视频教程</a>
  117. <p>Thinkphp6.0从2019年10月24日正式发布,相对测试版,有很多变动,目...</p>
  118. <span><i>中级</i>15926次播放</span>
  119. </span>
  120. </div>
  121. </section>
  122. <section>
  123. <div>
  124. <a href="#"><img src="static/images/03.jpg" alt=""></a>
  125. <span>
  126. <a href="#">2019python自学视频</a>
  127. <p>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带...</p>
  128. <span><i>初级</i>18359次播放</span>
  129. </span>
  130. </div>
  131. </section>
  132. <section>
  133. <div>
  134. <a href="#"><img src="static/images/4.png" alt=""></a>
  135. <span>
  136. <a href="#">PHP开发免费公益直播课</a>
  137. <p>主讲:php中文网-朱老师( Peter Zhu)时间:2019.10.17 晚 20:00-22:00...</p>
  138. <span><i>初级</i>4595次播放</span>
  139. </span>
  140. </div>
  141. </section>
  142. <section>
  143. <div>
  144. <a href="#"><img src="static/images/5.jpg" alt=""></a>
  145. <span>
  146. <a href="#">从零开始到WEB响应式布局</a>
  147. <p>重点介绍了HTML、CSS、web布局前端核心技术,通过视频讲解,了解...</p>
  148. <span><i>初级</i>19562次播放</span>
  149. </span>
  150. </div>
  151. </section>
  152. <section>
  153. <div>
  154. <a href="#"><img src="static/images/6.png" alt=""></a>
  155. <span>
  156. <a href="#">PHP文件基础操作</a>
  157. <p>好多同学在PHP基础的时候对PHP文件的操作了解的不够多,本节课就带...</p>
  158. <span><i>中级</i>6267次播放</span>
  159. </span>
  160. </div>
  161. </section>
  162. </article>
  163. <article class="recommend_new01">
  164. <h3>最新文章</h3>
  165. <section>
  166. <div>
  167. <span>
  168. <a href="#">workerman实现简单弹幕的方法</a>
  169. <span>发布时间:2020-02-03</span>
  170. </span>
  171. <a href="#"><img src="static/images/work.jpg" alt=""></a>
  172. </div>
  173. <div>
  174. <span>
  175. <a href="#">开发模式与产品模式下的PHP报错处理详解</a>
  176. <span>发布时间:2020-02-03</span>
  177. </span>
  178. <a href="#"><img src="static/images/php.jpg" alt=""></a>
  179. </div>
  180. <div>
  181. <span>
  182. <a href="#">怎么查看linux文件</a>
  183. <span>发布时间:2020-02-03</span>
  184. </span>
  185. <a href="#"><img src="static/images/linux.jpg" alt=""></a>
  186. </div>
  187. <div>
  188. <span>
  189. <a href="#">vscode怎么选择浏览器</a>
  190. <span>发布时间:2020-02-03</span>
  191. </span>
  192. <a href="#"><img src="static/images/vsvode1.jpg" alt=""></a>
  193. </div>
  194. <div>
  195. <span>
  196. <a href="#">vscode中的git是干啥的</a>
  197. <span>发布时间:2020-02-03</span>
  198. </span>
  199. <a href="#"><img src="static/images/vsvode2.jpg" alt=""></a>
  200. </div>
  201. <div>
  202. <span>
  203. <a href="#" style="text-align: center;margin-bottom: 10px;">更多内容</a>
  204. </span>
  205. </div>
  206. </section>
  207. </article>
  208. <article class="recommend_new02">
  209. <h3>最新博文</h3>
  210. <section>
  211. <div>
  212. <span>
  213. <a href="#">wordpress自动发送文章</a>
  214. <span>2020-01-21</span>
  215. </span>
  216. </div>
  217. <div>
  218. <span>
  219. <a href="#" style="margin-bottom: 10px;margin: 0 auto;padding-bottom: 10px;">更多内容</a>
  220. </span>
  221. </div>
  222. </section>
  223. </article>
  224. <article class="recommend_new03">
  225. <h3>最新最新问答</h3>
  226. <section>
  227. <div>
  228. <span>
  229. <a href="#">老师,视频里是不是有些代码有一些问题?</a>
  230. <span>2020-02-03</span>
  231. </span>
  232. </div>
  233. <div>
  234. <span>
  235. <a href="#">数据库无法启动</a>
  236. <span>2020-02-03</span>
  237. </span>
  238. </div>
  239. <div>
  240. <span>
  241. <a href="#">SQL链接出现1130</a>
  242. <span>2020-02-03</span>
  243. </span>
  244. </div>
  245. <div>
  246. <span>
  247. <a href="#">谷歌访问助手问题</a>
  248. <span>2020-02-02</span>
  249. </span>
  250. </div>
  251. <div>
  252. <span>
  253. <a href="#">new操作符的作用什么?</a>
  254. <span>2020-02-02</span>
  255. </span>
  256. </div>
  257. <div>
  258. <span>
  259. <a href="#" style="margin-bottom: 10px;margin: 0 auto;padding-bottom: 10px;">更多内容</a>
  260. </span>
  261. </div>
  262. </section>
  263. </article>
  264. </main>
  265. <!-- 底部菜单 -->
  266. <footer>
  267. <ul>
  268. <li>
  269. <a href="#" style="color: red;">
  270. <i class="iconfont icon-shouyeshouye" style="font-size: 18px;"></i>
  271. <span>首页</span>
  272. </a>
  273. </li>
  274. <li>
  275. <a href="#">
  276. <i class="iconfont icon-yunhang" style="font-size: 18px;"></i>
  277. <span>视频</span>
  278. </a>
  279. </li>
  280. <li>
  281. <a href="#">
  282. <i class="iconfont icon-ruanjiankaifabao" style="font-size: 18px;"></i>
  283. <span>社区</span>
  284. </a>
  285. </li>
  286. <li>
  287. <a href="#">
  288. <i class="iconfont icon-huiyuan2" style="font-size: 18px;"></i>
  289. <span>我的</span>
  290. </a>
  291. </li>
  292. </ul>
  293. </footer>
  294. </body>
  295. </html>

CSS代码

样式重置
  1. /* 初始化 */
  2. body,footer {
  3. /* 最小宽度设置 */
  4. min-width: 320px;
  5. /* 最大宽度设置 */
  6. max-width: 768px;
  7. /* 外边距上下清零,左右自动 */
  8. margin: 0 auto;
  9. /* 背景颜色 */
  10. background-color: #edeff0;
  11. /* Y轴初始化,默认值不显示滚动条 */
  12. overflow-y: initial;
  13. /* 相对定位 */
  14. position: relative;
  15. /* 字体颜色 */
  16. color: gray;
  17. /* 水平x轴隐藏滚动条 */
  18. overflow-x: hidden;
  19. /* 兼容苹果设备高亮设置 */
  20. -webkit-tap-highlight-color: transparent;
  21. }
  22. /* 设置所有图片全部自适应父容器 */
  23. img {
  24. width: 100%;
  25. }
  26. ul,li {
  27. /* 外边距清零 */
  28. margin: 0;
  29. /* 内边距清零 */
  30. padding: 0;
  31. }
  32. li {
  33. /* li前面的小黑点去掉 */
  34. list-style: none;
  35. }
  36. a {
  37. /* 文字下划线去掉 */
  38. text-decoration: none;
  39. /* 文字颜色 */
  40. color: gray;
  41. }
样式代码
  1. @import "reset.css";
  2. /* 头部样式 */
  3. header {
  4. /* 固定定位 */
  5. position: fixed;
  6. top: 0;
  7. width: 100%;
  8. min-width: 320px;
  9. max-width: 768px;
  10. height: 42px;
  11. background-color: #444444;
  12. color: #ffffff;
  13. /* 转为flex */
  14. display: flex;
  15. flex-direction: row;
  16. justify-content: space-between;
  17. align-items: center;
  18. }
  19. header > img:first-of-type,
  20. header > img:last-of-type {
  21. width: 26px;
  22. height: 26px;
  23. margin: 5px;
  24. }
  25. header > img:first-of-type {
  26. border-radius: 50%;
  27. }
  28. header > img {
  29. width: 94px;
  30. }
  31. /* 轮播图 */
  32. .banner {
  33. display: flex;
  34. height: 200px;
  35. }
  36. /* 导航区 */
  37. nav {
  38. /* 背景色 */
  39. background-color: #fff;
  40. /* 转为弹性布局 */
  41. display: flex;
  42. /* 主轴垂直方向,禁止换行 */
  43. flex-flow: column nowrap;
  44. }
  45. nav img {
  46. width: 45px;
  47. height: 49px;
  48. }
  49. nav > ul {
  50. display: flex;
  51. /* 主轴横向排练,禁止换行 */
  52. flex-flow: row nowrap;
  53. }
  54. nav ul li {
  55. flex: 1;
  56. }
  57. /* 图片文本作为一个整体,统一设置 */
  58. nav ul li a {
  59. display: flex;
  60. flex-flow: column wrap;
  61. align-items: center;
  62. margin: 10px;
  63. }
  64. nav ul li a span {
  65. margin-top: 5px;
  66. }
  67. /* 推荐课程 */
  68. main {
  69. display: flex;
  70. flex-direction: column;
  71. }
  72. main > .recommend > section:first-of-type {
  73. display: flex;
  74. }
  75. main > .recommend > section:first-of-type > a {
  76. margin: 5px;
  77. flex: 1;
  78. }
  79. main > .recommend > section:first-of-type > a > img {
  80. height: 90px;
  81. }
  82. /* 垂直排列的推荐课程 */
  83. main > .recommend > section:last-of-type {
  84. display: flex;
  85. flex-direction: column;
  86. }
  87. main > .recommend > section:last-of-type > div {
  88. background-color: #fff;
  89. margin: 5px;
  90. display: flex;
  91. }
  92. main > .recommend > section:last-of-type > div img {
  93. width: 350px;
  94. height: 80px;
  95. margin: 10px;
  96. }
  97. main > .recommend > section:last-of-type > div > span {
  98. flex: 1;
  99. display: flex;
  100. /* 垂直排列 */
  101. flex-direction: column;
  102. margin-top: 10px;
  103. padding-left: 10px;
  104. }
  105. main > .recommend > section:last-of-type > div > span i {
  106. /* 设置不斜体 */
  107. font-style: normal;
  108. background-color: #333333;
  109. color: white;
  110. border-radius: 6px;
  111. padding: 0 5px;
  112. font-size: smaller;
  113. line-height: 20px;
  114. }
  115. main > .recommend > section:last-of-type > div > span > span {
  116. margin-top: 40px;
  117. display: flex;
  118. justify-content: space-between;
  119. font-size: 14px;
  120. }
  121. body {
  122. height: 2810px;
  123. }
  124. footer {
  125. /* 固定定位 */
  126. position: fixed;
  127. bottom: 0;
  128. width: 100%;
  129. min-width: 320px;
  130. max-width: 768px;
  131. height: 42px;
  132. border-top: 1px solid #ccc;
  133. display: flex;
  134. flex-flow: column nowrap;
  135. }
  136. footer > ul {
  137. display: flex;
  138. /* 主轴横向排练,禁止换行 */
  139. flex-flow: row nowrap;
  140. }
  141. footer ul li {
  142. flex: 1;
  143. }
  144. footer ul li a {
  145. display: flex;
  146. flex-flow: column wrap;
  147. align-items: center;
  148. margin-top: 5px;
  149. }
  150. footer ul li a span {
  151. font-size: 15px;
  152. }
  153. footer ul li a:hover {
  154. color: red;
  155. }
  156. /* 垂直排列的最新更新 */
  157. main > .recommend_new > section {
  158. display: flex;
  159. flex-direction: column;
  160. }
  161. main > .recommend_new > section > div {
  162. background-color: #fff;
  163. margin:10px;
  164. display: flex;
  165. }
  166. main > .recommend_new > section > div img {
  167. width: 350px;
  168. height: 80px;
  169. margin: 10px;
  170. }
  171. main > .recommend_new > section > div > span {
  172. flex: 1;
  173. display: flex;
  174. /* 垂直排列 */
  175. flex-direction: column;
  176. margin-top: 15px;
  177. padding-left: 10px;
  178. }
  179. main > .recommend_new > section > div > span p {
  180. font-size: 11px;
  181. }
  182. main > .recommend_new > section > div > span i {
  183. /* 设置不斜体 */
  184. font-style: normal;
  185. background-color: #333333;
  186. color: white;
  187. border-radius: 6px;
  188. padding: 0 5px;
  189. font-size: smaller;
  190. line-height: 20px;
  191. }
  192. main > .recommend_new > section > div > span > span {
  193. display: flex;
  194. justify-content: space-between;
  195. font-size: 14px;
  196. }
  197. /* 垂直排列的最新文章 */
  198. main > .recommend_new01 > section {
  199. display: flex;
  200. flex-direction: column;
  201. }
  202. main > .recommend_new01 > section > div {
  203. background-color: #fff;
  204. margin: 5px;
  205. display: flex;
  206. }
  207. main > .recommend_new01 > section > div img {
  208. width: 275px;
  209. height: 65px;
  210. margin: 8px;
  211. }
  212. main > .recommend_new01 > section > div > span {
  213. flex: 1;
  214. display: flex;
  215. /* 垂直排列 */
  216. flex-direction: column;
  217. margin-top: 15px;
  218. padding-left: 10px;
  219. }
  220. main > .recommend_new01 > section > div > span > a {
  221. font-weight: bold;
  222. }
  223. main > .recommend_new01 > section > div > span > span {
  224. display: flex;
  225. justify-content: space-between;
  226. font-size: 15px;
  227. margin-top: 10px;
  228. }
  229. /* 垂直排列的最新博文 */
  230. main > .recommend_new02 > section {
  231. display: flex;
  232. flex-direction: column;
  233. }
  234. main > .recommend_new02 > section > div {
  235. background-color: #fff;
  236. margin: 5px;
  237. display: flex;
  238. }
  239. main > .recommend_new02 > section > div > span {
  240. flex: 1;
  241. display: flex;
  242. /* 垂直排列 */
  243. justify-content: space-between;
  244. margin-top: 15px;
  245. padding-left: 10px;
  246. }
  247. main > .recommend_new02 > section > div > span > a {
  248. font-weight: bold;
  249. }
  250. main > .recommend_new02 > section > div > span > span {
  251. display: flex;
  252. justify-content: space-between;
  253. font-size: 15px;
  254. margin: 10px;
  255. }
  256. /* 垂直排列的最新问答 */
  257. main > .recommend_new03 > section {
  258. display: flex;
  259. flex-direction: column;
  260. }
  261. main > .recommend_new03 > section > div {
  262. background-color: #fff;
  263. margin: 5px;
  264. display: flex;
  265. }
  266. main > .recommend_new03 > section > div > span {
  267. flex: 1;
  268. display: flex;
  269. /* 垂直排列 */
  270. justify-content: space-between;
  271. margin-top: 15px;
  272. padding-left: 10px;
  273. }
  274. main > .recommend_new03 > section > div > span > a {
  275. font-weight: bold;
  276. }
  277. main > .recommend_new03 > section > div > span > span {
  278. display: flex;
  279. justify-content: space-between;
  280. font-size: 15px;
  281. margin: 10px;
  282. }

效果如下




写完一个完整的首页后,前面一些模糊的问题好像有点清晰了,明白它的作用是什么。
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议