博客列表 >php中文网移动端首页布局实例(flex布局,包括字体图标的引用)

php中文网移动端首页布局实例(flex布局,包括字体图标的引用)

辛迪
辛迪原创
2020年04月15日 16:45:15517浏览

总结:通过以下实例,可对网页布局形成一个系统的概念,对网页布局的各部分源码有一个初步认识。实例中包括 html 中标签等的使用、css 中 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. <!-- 引入字体图标 -->
  7. <link rel="stylesheet" href="font-icon.css" />
  8. <title>php中文网</title>
  9. <style>
  10. /* 初始化 */
  11. * {
  12. margin: 0;
  13. padding: 0;
  14. }
  15. /* 设置链接样式 */
  16. a {
  17. text-decoration: none;
  18. color: gray;
  19. }
  20. /* 设置p标签颜色 */
  21. p {
  22. color: grey;
  23. }
  24. /* 设置网页宽度高度和大小 */
  25. html {
  26. width: 100vw;
  27. min-height: 100vw;
  28. font-size: 14px;
  29. }
  30. /* 主体区域样式 */
  31. body {
  32. min-width: 360px;
  33. background-color: #f1f0ef;
  34. display: flex;
  35. flex-flow: column nowrap;
  36. }
  37. /* 页眉样式 */
  38. body > header {
  39. background-color: rgb(31, 30, 30);
  40. height: 30px;
  41. color: white;
  42. display: flex;
  43. justify-content: space-between;
  44. align-items: center;
  45. padding: 5px 10px;
  46. position: fixed;
  47. width: 100vw;
  48. }
  49. /* 页眉中字体图标右侧内边距 */
  50. body > header .iconfont {
  51. padding-right: 20px;
  52. }
  53. /* 设置页眉中图片样式 */
  54. body > header > a > img {
  55. height: 50px;
  56. border-radius: 50%;
  57. }
  58. /* 轮播图样式 */
  59. body > .slider {
  60. margin-top: 20px;
  61. padding-bottom: 10px;
  62. background-color: #fff;
  63. }
  64. /* 设置轮播图中图片大小 */
  65. body > .slider > img {
  66. width: 100%;
  67. }
  68. /* 主导航区样式 */
  69. body > nav {
  70. display: flex;
  71. flex-flow: row wrap;
  72. padding: 15px;
  73. background-color: #fff;
  74. }
  75. /* 主导航区每个div占设备宽度的1/4 */
  76. body > nav > div {
  77. display: flex;
  78. flex-flow: column nowrap;
  79. width: 25%;
  80. align-items: center;
  81. padding-bottom: 10px;
  82. }
  83. /* 主导航区图片链接的对齐方式 */
  84. body > nav > div > a:first-of-type {
  85. text-align: center;
  86. }
  87. /* 主导航区图片宽度 */
  88. body > nav img {
  89. width: 50%;
  90. }
  91. /* 标题样式 */
  92. body > .title {
  93. font-size: 1.2rem;
  94. margin: 20px auto 10px 10px;
  95. font-weight: bold;
  96. }
  97. /* 推荐课程第一部分 */
  98. body > div > div:first-of-type {
  99. display: flex;
  100. margin: 0 5px;
  101. }
  102. /* 推荐课程第一部分内边距 */
  103. .item.kc > a {
  104. padding: 5px;
  105. }
  106. /* 推荐课程第一部分图片大小 */
  107. body > div > div:first-of-type > a > img {
  108. width: 100%;
  109. }
  110. /* 推荐课程,最新更新,最新文章,最新博文,最新问答设成flex */
  111. .tjkc2,
  112. .zxgx,
  113. .zxwz,
  114. .zxbw,
  115. .zxwd {
  116. display: flex;
  117. flex-flow: column nowrap;
  118. }
  119. /* 项目样式 */
  120. .item:not([class="item kc"]) {
  121. display: flex;
  122. justify-content: space-between;
  123. background-color: #fff;
  124. margin: 5px 10px;
  125. }
  126. /* 项目中的图片模块 */
  127. .itemimg {
  128. width: 70%;
  129. padding: 10px;
  130. }
  131. /* 项目中的图片模块的图片宽度 */
  132. .itemimg > img {
  133. width: 100%;
  134. }
  135. /* 项目标题样式 */
  136. .itemtitle:not([class="itemtitle wz"]):not([class="itemtitle bw"]) {
  137. padding-bottom: 5px;
  138. font-size: 1.2rem;
  139. }
  140. /* 课程级别样式 */
  141. .kcjb {
  142. color: honeydew;
  143. background-color: grey;
  144. border-radius: 30%;
  145. }
  146. /* 最新更新模块样式 */
  147. .item > span {
  148. display: flex;
  149. flex-flow: column nowrap;
  150. width: 100%;
  151. padding: 10px;
  152. }
  153. /* 推荐课程中课程描述模块 */
  154. .kcms {
  155. justify-content: space-between;
  156. }
  157. /* 课程级别行设为flex */
  158. .itemjb {
  159. display: flex;
  160. }
  161. /* 项目中各文字部分设为flex */
  162. body span > div:not([class="itemjb"]) {
  163. display: flex;
  164. justify-content: space-between;
  165. }
  166. /* 最新文章,最新博文文字描述标题加粗 */
  167. .itemtitle.wz,
  168. .itemtitle.bw {
  169. font-weight: bold;
  170. }
  171. /* 最新博文内容样式 */
  172. .item.bw,
  173. .item.wd {
  174. padding: 5px 10px;
  175. }
  176. /* 更多内容样式 */
  177. .gdnr {
  178. text-align: center;
  179. background-color: #fff;
  180. margin: 5px 10px;
  181. padding: 5px 0;
  182. }
  183. /* 距离页脚最近的项目距离底部设置外边距,不被页脚遮盖 */
  184. .gdnr.bottom {
  185. margin-bottom: 55px;
  186. }
  187. /* 页脚样式 */
  188. body > footer {
  189. display: flex;
  190. justify-content: space-around;
  191. align-items: center;
  192. border: 1px solid #c9c8c8;
  193. height: 45px;
  194. position: fixed;
  195. bottom: 0;
  196. width: 100vw;
  197. background-color: #f1f0ef;
  198. }
  199. /* 页脚中项目样式 */
  200. .itemyj {
  201. display: flex;
  202. flex-flow: column nowrap;
  203. align-items: center;
  204. width: 25%;
  205. }
  206. /* 字体图标大小 */
  207. .iconfont {
  208. font-size: 1.5rem;
  209. }
  210. /* 页脚“首页”红色 */
  211. .itemyj:first-of-type > a {
  212. color: red;
  213. }
  214. /* 设置一个空项目 */
  215. .kong {
  216. display: flex;
  217. margin-bottom: 40px;
  218. }
  219. </style>
  220. </head>
  221. <body>
  222. <!-- 页眉 -->
  223. <header>
  224. <span class="iconfont"> &#xe657; </span>
  225. <a href=""><img src="logo.png" alt="" /></a>
  226. <span class="iconfont"> &#xe611; </span>
  227. </header>
  228. <!-- 轮播图 -->
  229. <div class="slider">
  230. <img src="lb.png" />
  231. </div>
  232. <!-- 主导航 -->
  233. <nav>
  234. <div>
  235. <a href=""><img src="html.png" /></a>
  236. <a href="">HTML/CSS</a>
  237. </div>
  238. <div>
  239. <a href=""><img src="JavaScript.png" /></a>
  240. <a href="">JavaScript</a>
  241. </div>
  242. <div>
  243. <a href=""><img src="code.png" /></a>
  244. <a href="">服务端</a>
  245. </div>
  246. <div>
  247. <a href=""><img src="sql.png" /></a>
  248. <a href="">数据库</a>
  249. </div>
  250. <div>
  251. <a href=""><img src="app.png" /></a>
  252. <a href="">移动端</a>
  253. </div>
  254. <div>
  255. <a href=""><img src="manual.png" /></a>
  256. <a href="">手册</a>
  257. </div>
  258. <div>
  259. <a href=""><img src="tool2.png" /></a>
  260. <a href="">工具</a>
  261. </div>
  262. <div>
  263. <a href=""><img src="live.png" /></a>
  264. <a href="">直播</a>
  265. </div>
  266. </nav>
  267. <!-- 推荐课程 -->
  268. <p class="tjkc title">推荐课程</p>
  269. <div class="tjkc">
  270. <div class="item kc">
  271. <a href=""><img src="tjkc01.jpg" /></a>
  272. <a href=""><img src="tjkc02.jpg" /></a>
  273. </div>
  274. </div>
  275. <div class="tjkc2">
  276. <div class="item">
  277. <a href="" class="itemimg"><img src="tjkc03.jpg" /></a>
  278. <span class="wzms">
  279. <a href="" class="itemtitle">CI框架30分钟极速入门</a>
  280. <div class="itemjb">
  281. <p class="kcjb"> 中级 </p>
  282. <p>310590次播放</p>
  283. </div>
  284. </span>
  285. </div>
  286. <div class="item">
  287. <a href="" class="itemimg"><img src="tjkc04.jpg" /></a>
  288. <span class="wzms">
  289. <a href="" class="itemtitle">2018前端入门_HTML5</a>
  290. <div class="itemjb">
  291. <p class="kcjb"> 初级 </p>
  292. <p>310590次播放</p>
  293. </div>
  294. </span>
  295. </div>
  296. </div>
  297. <!-- 最新更新 -->
  298. <p class="zxgx title">最新更新</p>
  299. <div class="zxgx">
  300. <div class="item">
  301. <a href="" class="itemimg"><img src="zxgx01.png" /></a>
  302. <span class="kcms">
  303. <a href="" class="itemtitle">PHP快速操控Excel之PhpSpreadsheet</a>
  304. <p>
  305. 老的PHPExcel已经停止更新了...
  306. </p>
  307. <div>
  308. <p class="kcjb"> 中级 </p>
  309. <p>49598次播放</p>
  310. </div>
  311. </span>
  312. </div>
  313. <div class="item">
  314. <a href="" class="itemimg"><img src="zxgx02.png" /></a>
  315. <span class="kcms">
  316. <a href="" class="itemtitle">Thinkphp6.0正式版视频教程</a>
  317. <p>
  318. Thinkphp6.0从2019年10月24日正式发布...
  319. </p>
  320. <div>
  321. <p class="kcjb"> 中级 </p>
  322. <p>49598次播放</p>
  323. </div>
  324. </span>
  325. </div>
  326. <div class="item">
  327. <a href="" class="itemimg"><img src="zxgx03.jpg" /></a>
  328. <span class="kcms">
  329. <a href="" class="itemtitle">2019python自学视频</a>
  330. <p>
  331. 本课程适合想从零开始学习 Python 编程语言...
  332. </p>
  333. <div>
  334. <p class="kcjb"> 初级 </p>
  335. <p>49598次播放</p>
  336. </div>
  337. </span>
  338. </div>
  339. <div class="item">
  340. <a href="" class="itemimg"><img src="zxgx04.png" /></a>
  341. <span class="kcms">
  342. <a href="" class="itemtitle">PHP开发免费公益直播课</a>
  343. <p>
  344. 主讲:php中文网-朱老师( Peter Zhu) ...
  345. </p>
  346. <div>
  347. <p class="kcjb"> 初级 </p>
  348. <p>49598次播放</p>
  349. </div>
  350. </span>
  351. </div>
  352. <div class="item">
  353. <a href="" class="itemimg"><img src="zxgx05.jpg" /></a>
  354. <span class="kcms">
  355. <a href="" class="itemtitle">PHP开发免费公益直播课</a>
  356. <p>
  357. 主讲:php中文网-朱老师( Peter Zhu) ...
  358. </p>
  359. <div>
  360. <p class="kcjb"> 初级 </p>
  361. <p>49598次播放</p>
  362. </div>
  363. </span>
  364. </div>
  365. <div class="item">
  366. <a href="" class="itemimg"><img src="zxgx06.png" /></a>
  367. <span class="kcms">
  368. <a href="" class="itemtitle">PHP开发免费公益直播课</a>
  369. <p>
  370. 主讲:php中文网-朱老师( Peter Zhu) ...
  371. </p>
  372. <div>
  373. <p class="kcjb"> 中级 </p>
  374. <p>49598次播放</p>
  375. </div>
  376. </span>
  377. </div>
  378. </div>
  379. <!-- 最新文章 -->
  380. <p class="zxwz title">最新文章</p>
  381. <div class="zxwz">
  382. <div class="item">
  383. <span>
  384. <a href="" class="itemtitle wz">Web 服务器排行榜(2020年04月)</a>
  385. <a href=""><p>发布时间:2020-04-14</p></a>
  386. </span>
  387. <a href="" class="itemimg"><img src="zxwz01.jpg" /></a>
  388. </div>
  389. <div class="item">
  390. <span>
  391. <a href="" class="itemtitle wz">docker容器之间怎么互相调用</a>
  392. <a href=""><p>发布时间:2020-04-14</p></a>
  393. </span>
  394. <a href="" class="itemimg"><img src="zxwz02.png" /></a>
  395. </div>
  396. <div class="item">
  397. <span>
  398. <a href="" class="itemtitle wz">win10用u盘做开机密钥的方法</a>
  399. <a href=""><p>发布时间:2020-04-14</p></a>
  400. </span>
  401. <a href="" class="itemimg"><img src="zxwz03.jpg" /></a>
  402. </div>
  403. <div class="item">
  404. <span>
  405. <a href="" class="itemtitle wz">如何在mac上配置apache和php</a>
  406. <a href=""><p>发布时间:2020-04-14</p></a>
  407. </span>
  408. <a href="" class="itemimg"><img src="zxwz04.png" /></a>
  409. </div>
  410. <div class="item">
  411. <span>
  412. <a href="" class="itemtitle wz">蓝屏无法进入任何模式怎么办</a>
  413. <a href=""><p>发布时间:2020-04-14</p></a>
  414. </span>
  415. <a href="" class="itemimg"><img src="zxwz05.jpg" /></a>
  416. </div>
  417. <a href=""><p class="gdnr">更多内容</p></a>
  418. </div>
  419. <!-- 最新博文 -->
  420. <p class="zxwz title">最新博文</p>
  421. <div class="zxbw">
  422. <div class="item bw">
  423. <a href="" class="itemtitle bw">微信的openid和unionid</a>
  424. <a href=""><p>2020-04-14</p></a>
  425. </div>
  426. <div class="item bw">
  427. <a href="" class="itemtitle bw">JS实现HTML标签转义及反转义</a>
  428. <a href=""><p>2020-04-14</p></a>
  429. </div>
  430. <div class="item bw">
  431. <a href="" class="itemtitle bw"
  432. >细说选择器:简单选择器、上下文选择器、伪类选择器、其它选择器</a
  433. >
  434. <a href=""><p>2020-04-14</p></a>
  435. </div>
  436. <div class="item bw">
  437. <a href="" class="itemtitle bw">CSS 中各类选择器的属性及应用</a>
  438. <a href=""><p>2020-04-14</p></a>
  439. </div>
  440. <div class="item bw">
  441. <a href="" class="itemtitle bw">CSS3:弹性盒子flex布局</a>
  442. <a href=""><p>2020-04-14</p></a>
  443. </div>
  444. <a href=""><p class="gdnr">更多内容</p></a>
  445. </div>
  446. <!-- 最新问答 -->
  447. <p class="zxwz title">最新问答</p>
  448. <div class="zxwd">
  449. <div class="item wd">
  450. <a href="" class="itemtitle bw">免费的虚拟主机分享</a>
  451. <a href=""><p>2020-04-14</p></a>
  452. </div>
  453. <div class="item wd">
  454. <a href="" class="itemtitle bw">登陆验证出错</a>
  455. <a href=""><p>2020-04-14</p></a>
  456. </div>
  457. <div class="item wd">
  458. <a href="" class="itemtitle bw">请教thinkPHP安装问题</a>
  459. <a href=""><p>2020-04-14</p></a>
  460. </div>
  461. <div class="item wd">
  462. <a href="" class="itemtitle bw">输入cmd命令</a>
  463. <a href=""><p>2020-04-14</p></a>
  464. </div>
  465. <div class="item wd">
  466. <a href="" class="itemtitle bw">cmd输入出现这个问题是怎么回事</a>
  467. <a href=""><p>2020-04-14</p></a>
  468. </div>
  469. <a href=""><p class="gdnr bottom">更多内容</p></a>
  470. </div>
  471. <!-- 页脚 -->
  472. <footer>
  473. <div class="itemyj">
  474. <a href=""><span class="iconfont"> &#xe64a; </span></a>
  475. <a href="">首页</a>
  476. </div>
  477. <div class="itemyj">
  478. <a href=""><span class="iconfont"> &#xe637; </span></a>
  479. <a href="">视频</a>
  480. </div>
  481. <div class="itemyj">
  482. <a href=""><span class="iconfont"> &#xe8b8; </span></a>
  483. <a href="">社区</a>
  484. </div>
  485. <div class="itemyj">
  486. <a href=""><span class="iconfont"> &#xe60e; </span></a>
  487. <a href="">我的</a>
  488. </div>
  489. </footer>
  490. </body>
  491. </html>

引用字体图标

首页布局中需要引用字体图标,引用方式如下:

<!-- 以下字体图标的引用方式为字体编码引入 -->

  1. <link rel="stylesheet" href="font-icon.css" />
  1. <body>
  2. <a href=""><span class="iconfont"></span></a>
  3. </body>

字体图标的下载方式(以阿里图标为例):

  • 1、在浏览器中搜索“阿里图标”,点击“Iconfont-阿里巴巴矢量图标库”。

    搜索阿里图标

  • 2、打开“Iconfont-阿里巴巴矢量图标库”,选择需要的字体库点击打开字体库。

    字体库

  • 3、选择需要的字体图标加入购物车。

    加入购物车

  • 4、点击购物车,下载代码。

    购物车

  • 5、下载的是一个名为“download.zip”的压缩包,解压缩后为字体文件夹。

  • 6、打开文件夹中的“demo_index.html”,根据说明引用字体图标。

Unicode 使用步骤如下:

<!-- 也可以font-class 引用、Symbol 引用 -->

第一步:拷贝项目下面生成的@font-face

  1. @font-face {
  2. font-family: "iconfont";
  3. src: url("iconfont.eot");
  4. src: url("iconfont.eot?#iefix") format("embedded-opentype"), url("iconfont.woff2")
  5. format("woff2"), url("iconfont.woff") format("woff"), url("iconfont.ttf")
  6. format("truetype"), url("iconfont.svg#iconfont") format("svg");
  7. }

第二步:定义使用 iconfont 的样式

  1. .iconfont {
  2. font-family: "iconfont" !important;
  3. font-size: 16px;
  4. font-style: normal;
  5. -webkit-font-smoothing: antialiased;
  6. -moz-osx-font-smoothing: grayscale;
  7. }

第三步:挑选相应图标并获取字体编码,应用于页面

  1. <span class="iconfont"> &#x33; </span>

&#x33;为所需要的字体图标的编码,在“demo_index.html”中选择需要的字体图标的编码。

网页中引入的 css 文件

font-icon.css

  1. @font-face {
  2. font-family: "iconfont";
  3. /* 所有的url地址根据实际路径修改 */
  4. src: url("font_icon/iconfont.eot");
  5. src: url("font_icon/iconfont.eot?#iefix") format("embedded-opentype"), url("font_icon/iconfont.woff2")
  6. format("woff2"), url("font_icon/iconfont.woff") format("woff"), url("font_icon/iconfont.ttf")
  7. format("truetype"), url("font_icon/iconfont.svg#iconfont") format("svg");
  8. }
  9. .iconfont {
  10. font-family: "iconfont" !important;
  11. font-size: 16px;
  12. font-style: normal;
  13. -webkit-font-smoothing: antialiased;
  14. -moz-osx-font-smoothing: grayscale;
  15. }

网页实例效果

实例效果图1

实例效果图2

实例效果图3

实例效果图4

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