博客列表 >html学习:大作业: 使用flex布局实现php中文网移动端网页布局

html学习:大作业: 使用flex布局实现php中文网移动端网页布局

王小飞
王小飞原创
2020年05月20日 17:49:06960浏览

代码:

  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>手写php中文网移动端</title>
  7. <!-- <link rel="stylesheet" href="icon.css" /> -->
  8. <style>
  9. @font-face {
  10. font-family: "iconfont";
  11. src: url("font_mices8wnt5/iconfont.eot");
  12. src: url("font_mices8wnt5/iconfont.eot?#iefix")
  13. format("embedded-opentype"),
  14. url("font_mices8wnt5/iconfont.woff2") format("woff2"),
  15. url("font_mices8wnt5/iconfont.woff") format("woff"),
  16. url("font_mices8wnt5/iconfont.ttf") format("truetype"),
  17. url("font_mices8wnt5/iconfont.svg#iconfont") format("svg");
  18. }
  19. .iconfont {
  20. font-family: "iconfont" !important;
  21. font-size: 16px;
  22. font-style: normal;
  23. -webkit-font-smoothing: antialiased;
  24. -moz-osx-font-smoothing: grayscale;
  25. }
  26. html {
  27. /* vw: 每个容器/可视区宽度,100vw:表示占满100份 */
  28. width: 100vw;
  29. /* 可视高度也是100份 */
  30. height: 100vh;
  31. /* 在html中设置字体大小, 给后的rem单位用 */
  32. font-size: 14px;
  33. }
  34. * body {
  35. /* 设置外边框 内边框为0 */
  36. margin: 0;
  37. padding: 0;
  38. /* 设置底色 */
  39. background-color: rgb(219, 219, 219);
  40. display: flex;
  41. /* 纵向排列 不换行 */
  42. flex-flow: column nowrap;
  43. }
  44. a {
  45. /* a标签去掉下划线 */
  46. text-decoration: none;
  47. /* 设置文字颜色 */
  48. color: #666;
  49. }
  50. body > header {
  51. display: flex;
  52. background-color: rgb(29, 23, 23);
  53. /* 设置导航栏高度 */
  54. height: 45px;
  55. /* 设置导航栏宽度为自适应 */
  56. width: 100%;
  57. }
  58. body > header {
  59. display: flex;
  60. /* 垂直居中 */
  61. align-items: center;
  62. /* 设置三个图片分散对齐 */
  63. justify-content: space-around;
  64. }
  65. /* 选择导航的第一个a标签 */
  66. header a:first-of-type {
  67. display: flex;
  68. height: 30px;
  69. width: 30px;
  70. /* 距离左边距离 */
  71. margin-left: -40px;
  72. }
  73. /* 选择导航的第二个a标签 */
  74. header a:nth-child(2) {
  75. display: flex;
  76. height: 50px;
  77. width: 100px;
  78. }
  79. /* 选择导航的最后一个a标签 */
  80. header a:last-of-type {
  81. display: flex;
  82. margin-right: -40px;
  83. }
  84. body > .hdp {
  85. display: flex;
  86. /* 设置图片高度 */
  87. height: 150px;
  88. }
  89. body > .hdp > a > img {
  90. /* 图片宽度百分之百适应当前容器大小 */
  91. width: 100%;
  92. }
  93. nav {
  94. background-color: rgb(255, 253, 253);
  95. /* 高度 */
  96. height: 170px;
  97. display: flex;
  98. /* 变成多行容器 */
  99. flex-flow: row wrap;
  100. }
  101. nav > div {
  102. display: flex;
  103. width: 25vw;
  104. /* 弹性盒子 主轴垂直 不换行 */
  105. flex-flow: column nowrap;
  106. /* 交叉轴对齐 */
  107. align-items: center;
  108. /* 距离顶部边距 */
  109. margin-top: 10px;
  110. }
  111. nav > div > a:first-of-type {
  112. /* 图片主轴居中 */
  113. text-align: center;
  114. }
  115. nav > div img {
  116. /* 缩小图片 */
  117. width: 50%;
  118. }
  119. h2 {
  120. /* 距离顶部边距 */
  121. margin-top: 25px;
  122. /* 距离左边边距 */
  123. margin-left: 11px;
  124. color: rgba(102, 102, 102, 0.76);
  125. /* 文字大小1.2倍 */
  126. font-size: 1.3rem;
  127. }
  128. .tuijian1 {
  129. display: flex;
  130. /* 设置图片高度 */
  131. height: 100px;
  132. /* 分散对齐 */
  133. }
  134. .tuijian1 > a > img {
  135. /* 图片宽度百分之百适应当前容器大小 */
  136. margin: 0;
  137. padding: 0;
  138. /* 距离左边边距 */
  139. margin-left: 10px;
  140. /* 设置高度 */
  141. height: 95px;
  142. }
  143. .tuijian2 {
  144. background-color: rgb(255, 251, 251);
  145. display: flex;
  146. /* 纵向排列不换行 */
  147. /* flex-flow: column nowrap; */
  148. height: 102px;
  149. margin-top: 15px;
  150. width: 96%;
  151. margin-left: 7px;
  152. }
  153. .tuijian2 > div > a > img {
  154. height: 80px;
  155. margin-left: 10px;
  156. margin-top: 11px;
  157. }
  158. .tuijian2b {
  159. margin-top: 10px;
  160. margin-left: 8px;
  161. }
  162. .zjwz {
  163. margin-top: 10px;
  164. background-color: rgb(255, 251, 251);
  165. height: 80px;
  166. width: 96%;
  167. }
  168. .zjwzz {
  169. /* 纵向排列不换行 */
  170. display: flex;
  171. white-space: nowrap;
  172. }
  173. .zjwz > .zjwzz > .zjwzzz {
  174. margin-top: 10px;
  175. margin-left: 5px;
  176. font-size: 16px;
  177. }
  178. .zjwz > .zjwzz > .zjwzzz > span {
  179. font-size: 12px;
  180. color: rgba(102, 102, 102, 0.76);
  181. }
  182. .zjwzz > div > a > img {
  183. height: 65px;
  184. width: 100%;
  185. margin-left: 80px;
  186. margin-top: 10px;
  187. }
  188. .gdnr {
  189. margin-top: 10px;
  190. background-color: rgb(255, 251, 251);
  191. height: 35px;
  192. }
  193. footer {
  194. width: 100vw;
  195. height: 6vh;
  196. background-color: rgb(90, 89, 89);
  197. display: flex;
  198. justify-content: space-evenly;
  199. align-items: center;
  200. box-sizing: border-box;
  201. position: fixed;
  202. bottom: 0;
  203. }
  204. footer > div {
  205. display: flex;
  206. flex-flow: column nowrap;
  207. color: lightgray;
  208. align-items: center;
  209. font-size: 0.8rem;
  210. margin: 1vh 0;
  211. }
  212. footer > div > :first-of-type {
  213. font-size: 2rem;
  214. }
  215. footer > div:hover {
  216. color: lightsalmon;
  217. }
  218. </style>
  219. </head>
  220. <body>
  221. <!-- 页头 -->
  222. <header>
  223. <a href=""><img src="login.png" alt="" /></a>
  224. <a href=""><img src="logo.png" alt="" /></a>
  225. <a href=""><img src="an.png" alt="" /></a>
  226. </header>
  227. <!-- 幻灯片 -->
  228. <div class="hdp">
  229. <a href=""><img src="2.jpg" alt="" /></a>
  230. </div>
  231. <!-- 主体导航 -->
  232. <nav>
  233. <div>
  234. <a href=""><img src="html.png" alt="" /> </a><a href="">工具</a>
  235. </div>
  236. <div>
  237. <a href=""><img src="JavaScript.png" alt="" /> </a><a href="">手册</a>
  238. </div>
  239. <div>
  240. <a href=""><img src="html.png" alt="" /> </a><a href="">服务器</a>
  241. </div>
  242. <div>
  243. <a href=""><img src="JavaScript.png" alt="" /> </a><a href="">直播</a>
  244. </div>
  245. <div>
  246. <a href=""><img src="html.png" alt="" /> </a><a href="">数据库</a>
  247. </div>
  248. <div>
  249. <a href=""><img src="JavaScript.png" alt="" /> </a><a href="">移动端</a>
  250. </div>
  251. <div>
  252. <a href=""><img src="html.png" alt="" /> </a><a href="">php</a>
  253. </div>
  254. <div>
  255. <a href=""><img src="JavaScript.png" alt="" /> </a><a href="">css</a>
  256. </div>
  257. </nav>
  258. <!-- 推荐课程 标题 -->
  259. <h2>推荐课程</h2>
  260. <!-- 推荐课程 内容 -->
  261. <div>
  262. <div class="tuijian1">
  263. <a href=""><img src="5d242759adb88970.jpg" alt="" /></a>
  264. <a href=""><img src="5d242759adb88970.jpg" alt="" /></a>
  265. </div>
  266. <div>
  267. <div class="tuijian2">
  268. <div>
  269. <a href=""><img src="5d2941e265889366.jpg" alt="" /> </a>
  270. </div>
  271. <div class="tuijian2b">
  272. <div>
  273. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a>
  274. </div>
  275. <p>
  276. <span
  277. style="background-color: #575050; color: rgb(255, 248, 248);"
  278. >中级</span
  279. ><span style="color: rgba(153, 147, 147, 0.808);"
  280. >61815次播放</span
  281. >
  282. </p>
  283. </div>
  284. </div>
  285. </div>
  286. <div>
  287. <div class="tuijian2">
  288. <div>
  289. <a href=""><img src="5d2941e265889366.jpg" alt="" /> </a>
  290. </div>
  291. <div class="tuijian2b">
  292. <div>
  293. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a>
  294. </div>
  295. <p>
  296. <span
  297. style="background-color: #575050; color: rgb(255, 248, 248);"
  298. >中级</span
  299. ><span style="color: rgba(153, 147, 147, 0.808);"
  300. >61815次播放</span
  301. >
  302. </p>
  303. </div>
  304. </div>
  305. </div>
  306. </div>
  307. <!-- 最近更新 标题 -->
  308. <h2>最近更新</h2>
  309. <!-- 最近更新 内容 -->
  310. <div>
  311. <div>
  312. <div class="tuijian2">
  313. <div>
  314. <a href=""><img src="5aa23f0ded921649.jpg" alt="" /> </a>
  315. </div>
  316. <div class="tuijian2b">
  317. <div>
  318. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a><br />
  319. <a
  320. href=""
  321. style="font-size: 11px; color: rgba(153, 147, 147, 0.808"
  322. >CI框架30分钟极速入门CI框架30分钟极速入门CI框架30分钟极速入门</a
  323. >
  324. </div>
  325. <p>
  326. <span
  327. style="background-color: #575050; color: rgb(255, 248, 248);"
  328. >中级</span
  329. ><span style="color: rgba(153, 147, 147, 0.808);"
  330. >61815次播放</span
  331. >
  332. </p>
  333. </div>
  334. </div>
  335. </div>
  336. </div>
  337. <div>
  338. <div>
  339. <div class="tuijian2">
  340. <div>
  341. <a href=""><img src="5aa23f0ded921649.jpg" alt="" /> </a>
  342. </div>
  343. <div class="tuijian2b">
  344. <div>
  345. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a><br />
  346. <a
  347. href=""
  348. style="font-size: 11px; color: rgba(153, 147, 147, 0.808"
  349. >CI框架30分钟极速入门CI框架30分钟极速入门CI框架30分钟极速入</a
  350. >
  351. </div>
  352. <p>
  353. <span
  354. style="background-color: #575050; color: rgb(255, 248, 248);"
  355. >中级</span
  356. >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<span
  357. style="color: rgba(153, 147, 147, 0.808);"
  358. >61815次播放</span
  359. >
  360. </p>
  361. </div>
  362. </div>
  363. </div>
  364. </div>
  365. <div>
  366. <div>
  367. <div class="tuijian2">
  368. <div>
  369. <a href=""><img src="5aa23f0ded921649.jpg" alt="" /> </a>
  370. </div>
  371. <div class="tuijian2b">
  372. <div>
  373. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a><br />
  374. <a
  375. href=""
  376. style="font-size: 11px; color: rgba(153, 147, 147, 0.808"
  377. >CI框架30分钟极速入门CI框架30分钟极速入门CI框架30分钟极速入门</a
  378. >
  379. </div>
  380. <p>
  381. <span
  382. style="background-color: #575050; color: rgb(255, 248, 248);"
  383. >中级</span
  384. >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<span
  385. style="color: rgba(153, 147, 147, 0.808);"
  386. >61815次播放</span
  387. >
  388. </p>
  389. </div>
  390. </div>
  391. </div>
  392. </div>
  393. <div>
  394. <div>
  395. <div class="tuijian2">
  396. <div>
  397. <a href=""><img src="5aa23f0ded921649.jpg" alt="" /> </a>
  398. </div>
  399. <div class="tuijian2b">
  400. <div>
  401. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a><br />
  402. <a
  403. href=""
  404. style="font-size: 11px; color: rgba(153, 147, 147, 0.808"
  405. >CI框架30分钟极速入门CI框架30分钟极速入门CI框架30分钟极速入门</a
  406. >
  407. </div>
  408. <p>
  409. <span
  410. style="background-color: #575050; color: rgb(255, 248, 248);"
  411. >中级</span
  412. >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<span
  413. style="color: rgba(153, 147, 147, 0.808);"
  414. >61815次播放</span
  415. >
  416. </p>
  417. </div>
  418. </div>
  419. </div>
  420. </div>
  421. <div>
  422. <div>
  423. <div class="tuijian2">
  424. <div>
  425. <a href=""><img src="5aa23f0ded921649.jpg" alt="" /> </a>
  426. </div>
  427. <div class="tuijian2b">
  428. <div>
  429. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a><br />
  430. <a
  431. href=""
  432. style="font-size: 11px; color: rgba(153, 147, 147, 0.808"
  433. >CI框架30分钟极速入门CI框架30分钟极速入门CI框架30分钟极速入门</a
  434. >
  435. </div>
  436. <p>
  437. <span
  438. style="background-color: #575050; color: rgb(255, 248, 248);"
  439. >中级</span
  440. >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<span
  441. style="color: rgba(153, 147, 147, 0.808);"
  442. >61815次播放</span
  443. >
  444. </p>
  445. </div>
  446. </div>
  447. </div>
  448. </div>
  449. <div>
  450. <div>
  451. <div class="tuijian2">
  452. <div>
  453. <a href=""><img src="5aa23f0ded921649.jpg" alt="" /> </a>
  454. </div>
  455. <div class="tuijian2b">
  456. <div>
  457. <a href="" style="font-size: 17px;">CI框架30分钟极速入门</a><br />
  458. <a
  459. href=""
  460. style="font-size: 11px; color: rgba(153, 147, 147, 0.808"
  461. >CI框架30分钟极速入门CI框架30分钟极速入门CI框架30分钟极速入门</a
  462. >
  463. </div>
  464. <p>
  465. <span
  466. style="background-color: #575050; color: rgb(255, 248, 248);"
  467. >中级</span
  468. >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<span
  469. style="color: rgba(153, 147, 147, 0.808);"
  470. >61815次播放</span
  471. >
  472. </p>
  473. </div>
  474. </div>
  475. </div>
  476. </div>
  477. <!-- 最近文章 标题 -->
  478. <h2>最新文章</h2>
  479. <!-- 最近文章 内容 -->
  480. <div class="zjwz">
  481. <div class="zjwzz">
  482. <div class="zjwzzz">
  483. <a href="">文章标题文章标题标题</a><br />
  484. <br />
  485. <span>发布时间:2020-04-22</span>
  486. </div>
  487. <div>
  488. <a href=""
  489. ><img style="width: 100px;" src="5e9fe33197a93614.jpg" alt=""
  490. /></a>
  491. </div>
  492. </div>
  493. </div>
  494. <div class="zjwz">
  495. <div class="zjwzz">
  496. <div class="zjwzzz">
  497. <a href="">文章标题文章标题标题</a><br />
  498. <br />
  499. <span>发布时间:2020-04-22</span>
  500. </div>
  501. <div>
  502. <a href=""
  503. ><img style="width: 100px;" src="5e9fe33197a93614.jpg" alt=""
  504. /></a>
  505. </div>
  506. </div>
  507. </div>
  508. <div class="zjwz">
  509. <div class="zjwzz">
  510. <div class="zjwzzz">
  511. <a href="">文章标题文章标题标题</a><br />
  512. <br />
  513. <span>发布时间:2020-04-22</span>
  514. </div>
  515. <div>
  516. <a href=""
  517. ><img style="width: 100px;" src="5e9fe33197a93614.jpg" alt=""
  518. /></a>
  519. </div>
  520. </div>
  521. </div>
  522. <div class="zjwz">
  523. <div class="zjwzz">
  524. <div class="zjwzzz">
  525. <a href="">文章标题文章标题标题</a><br />
  526. <br />
  527. <span>发布时间:2020-04-22</span>
  528. </div>
  529. <div>
  530. <a href=""
  531. ><img style="width: 100px;" src="5e9fe33197a93614.jpg" alt=""
  532. /></a>
  533. </div>
  534. </div>
  535. </div>
  536. <div class="zjwz">
  537. <div class="zjwzz">
  538. <div class="zjwzzz">
  539. <a href="">文章标题文章标题标题</a><br />
  540. <br />
  541. <span>发布时间:2020-04-22</span>
  542. </div>
  543. <div>
  544. <a href=""
  545. ><img style="width: 100px;" src="5e9fe33197a93614.jpg" alt=""
  546. /></a>
  547. </div>
  548. </div>
  549. </div>
  550. <div class="gdnr"><p>更多内容</p></div>
  551. <!-- 页脚 -->
  552. <footer>
  553. <div>
  554. <span class="iconfont">&#xe6ef;</span>
  555. <span>首页</span>
  556. </div>
  557. <div>
  558. <span class="iconfont">&#xe72f;</span>
  559. <span>视频</span>
  560. </div>
  561. <div>
  562. <span class="iconfont">&#xe744;</span>
  563. <span>社区</span>
  564. </div>
  565. <div>
  566. <span class="iconfont">&#xe6f0;</span>
  567. <span>我的</span>
  568. </div>
  569. </footer>
  570. <!-- 页脚 -->
  571. </body>
  572. </html>

效果

效果gif:

总结:第一次自己写前段,写了好几天。这个写的 只有在火狐访问好看,其它浏览器都好丑

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