Blogger Information
Blog 7
fans 0
comment 0
visits 4340
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用flex仿PHP中文网移动端页面(1227)
建国
Original
763 people have browsed it

内容

尽可能使用flex仿照PHP中文网移动端做一个页面,练习flex的使用

代码

html部分

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui">
  7. <link rel="stylesheet" href="./static/css/style.css">
  8. <link rel="stylesheet" href="./static/font/iconfont.css">
  9. <title>flex练习-仿php中文网移动端首页</title>
  10. <style>
  11. </style>
  12. </head>
  13. <body>
  14. <!--头部-->
  15. <header>
  16. <a href=""><img src="./static/images/user_avatar.jpg" alt=""></a>
  17. <a href=""><img src="./static/images/logo.png" alt=""></a>
  18. <span><i class="iconfont icon-menu-fold"></i></span>
  19. </header>
  20. <!--主体部分-->
  21. <main>
  22. <!-- banner图-->
  23. <div class="banner">
  24. <a href=""><img src="./static/images/bannerr.jpg" alt=""></a>
  25. </div>
  26. <!-- 快速入口-->
  27. <div class="quick-entry">
  28. <div>
  29. <a href=""><img src="./static/images/html.png" alt=""></a>
  30. <a>HTML/CSS</a>
  31. </div>
  32. <div>
  33. <a href=""><img src="./static/images/JavaScript.png" alt=""></a>
  34. <a>JavaScript</a>
  35. </div>
  36. <div>
  37. <a href=""><img src="./static/images/code.png" alt=""></a>
  38. <a>服务端</a>
  39. </div>
  40. <div>
  41. <a href=""><img src="./static/images/sql.png" alt=""></a>
  42. <a>数据库</a>
  43. </div>
  44. <div>
  45. <a href=""><img src="./static/images/app.png" alt=""></a>
  46. <a>移动端</a>
  47. </div>
  48. <div>
  49. <a href=""><img src="./static/images/manual.png" alt=""></a>
  50. <a>手册</a>
  51. </div>
  52. <div>
  53. <a href=""><img src="./static/images/tool2.png" alt=""></a>
  54. <a>工具</a>
  55. </div>
  56. <div>
  57. <a href=""><img src="./static/images/live.png" alt=""></a>
  58. <a>直播</a>
  59. </div>
  60. </div>
  61. <div class="lesson">
  62. <!-- 推荐课程-->
  63. <span class="title">推荐课程</span>
  64. <!-- 广告-->
  65. <div class="ads">
  66. <a href=""><img src="./static/images/5d242759adb88970.jpg" alt=""></a>
  67. <a href=""><img src="./static/images/5d242759adb88970.jpg" alt=""></a>
  68. </div>
  69. <div class="lesson-detail">
  70. <a href=""><img src="./static/images/5d2941e265889366.jpg" alt=""></a>
  71. <div>
  72. <a href="">CI框架30分钟快速入门</a>
  73. <div>
  74. <span>中级</span>
  75. <span>55694次播放</span>
  76. </div>
  77. </div>
  78. </div>
  79. <div class="lesson-detail">
  80. <a href=""><img src="./static/images/5d2941e265889366.jpg" alt=""></a>
  81. <div>
  82. <a href="">CI框架30分钟快速入门</a>
  83. <div>
  84. <span>中级</span>
  85. <span>55694次播放</span>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="lesson">
  91. <!-- 最新更新-->
  92. <span class="title">最新更新</span>
  93. <div class="lesson-detail">
  94. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  95. <div class="new">
  96. <a href="">2019python自学视频</a>
  97. <span>本课程适合想从零开始学习Python编程语言的开发人员。由浅入深的带</span>
  98. <div>
  99. <span>初级</span>
  100. <span>55694次播放</span>
  101. </div>
  102. </div>
  103. </div>
  104. <div class="lesson-detail">
  105. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  106. <div class="new">
  107. <a href="">2019python自学视频</a>
  108. <span>本课程适合想从零开始学习Python编程语言的开发人员。由浅入深的带</span>
  109. <div>
  110. <span>初级</span>
  111. <span>55694次播放</span>
  112. </div>
  113. </div>
  114. </div>
  115. <div class="lesson-detail">
  116. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  117. <div class="new">
  118. <a href="">2019python自学视频</a>
  119. <span>本课程适合想从零开始学习Python编程语言的开发人员。由浅入深的带</span>
  120. <div>
  121. <span>初级</span>
  122. <span>55694次播放</span>
  123. </div>
  124. </div>
  125. </div>
  126. <div class="lesson-detail">
  127. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  128. <div class="new">
  129. <a href="">2019python自学视频</a>
  130. <span>本课程适合想从零开始学习Python编程语言的开发人员。由浅入深的带</span>
  131. <div>
  132. <span>初级</span>
  133. <span>55694次播放</span>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. <div class="lesson">
  139. <!-- 最新文章-->
  140. <span class="title">最新文章</span>
  141. <div class="lesson-detail article">
  142. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  143. <div>
  144. <a href="">利用CSRF令牌验证机制漏洞验证受害者账户</a>
  145. <span>发布时间:2019-12-28</span>
  146. </div>
  147. </div>
  148. <div class="lesson-detail article">
  149. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  150. <div>
  151. <a href="">利用CSRF令牌验证机制漏洞验证受害者账户</a>
  152. <span>发布时间:2019-12-28</span>
  153. </div>
  154. </div>
  155. <div class="lesson-detail article">
  156. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  157. <div>
  158. <a href="">利用CSRF令牌验证机制漏洞验证受害者账户</a>
  159. <span>发布时间:2019-12-28</span>
  160. </div>
  161. </div>
  162. <div class="lesson-detail article">
  163. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  164. <div>
  165. <a href="">利用CSRF令牌验证机制漏洞验证受害者账户</a>
  166. <span>发布时间:2019-12-28</span>
  167. </div>
  168. </div>
  169. <div class="lesson-detail article">
  170. <a href=""><img src="./static/images/aaa.jpg" alt=""></a>
  171. <div>
  172. <a href="">利用CSRF令牌验证机制漏洞验证受害者账户</a>
  173. <span>发布时间:2019-12-28</span>
  174. </div>
  175. </div>
  176. <a href="" class="more">更多内容</a>
  177. </div>
  178. <div class="blog">
  179. <!-- 最新博文-->
  180. <span class="title">最新博文</span>
  181. <div class="blogdetail">
  182. <span><a href="">composer安装laravel,nginx服务器配置解决404问题,创建简单的控制器</a></span>
  183. <span>2019-12-27</span>
  184. </div>
  185. <div class="blogdetail">
  186. <span><a href="">composer安装laravel,nginx服务器配置解决404问题,创建简单的控制器</a></span>
  187. <span>2019-12-27</span>
  188. </div>
  189. <div class="blogdetail">
  190. <span><a href="">composer安装laravel,nginx服务器配置解决404问题,创建简单的控制器</a></span>
  191. <span>2019-12-27</span>
  192. </div>
  193. <div class="blogdetail">
  194. <span><a href="">composer安装laravel,nginx服务器配置解决404问题,创建简单的控制器</a></span>
  195. <span>2019-12-27</span>
  196. </div>
  197. <div class="blogdetail">
  198. <span><a href="">composer安装laravel,nginx服务器配置解决404问题,创建简单的控制器</a></span>
  199. <span>2019-12-27</span>
  200. </div>
  201. <a href="" class="more">更多内容</a>
  202. </div>
  203. </main>
  204. <footer>
  205. <div class="active">
  206. <span><i class="iconfont icon-home"></i></span>
  207. <span>首页</span>
  208. </div>
  209. <div>
  210. <span><i class="iconfont icon-play"></i></span>
  211. <span>视频</span>
  212. </div>
  213. <div>
  214. <span><i class="iconfont icon-codeschool"></i></span>
  215. <span>社区</span>
  216. </div>
  217. <div>
  218. <span><i class="iconfont icon-user"></i></span>
  219. <span>我的</span>
  220. </div>
  221. </footer>
  222. </body>
  223. </html>

CSS部分

  1. /*样式初始化*/
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. }
  6. body {
  7. width: 100vw;
  8. height: 100vh;
  9. /*转为flex容器*/
  10. /*display: flex;*/
  11. /*垂直方向*/
  12. /*flex-direction: column;*/
  13. background-color: #edeff0;
  14. box-sizing: border-box;
  15. min-width: 360px;
  16. font-size: 14px;
  17. }
  18. li {
  19. list-style: none
  20. }
  21. a {
  22. text-decoration: none
  23. }
  24. /*样式初始化结束*/
  25. /*字体图标*/
  26. @font-face {
  27. font-family: "iconfont";
  28. src: url('https://at.alicdn.com/t/font_985780_km7mi63cihi.eot?t=1545807318834');
  29. src: url('https://at.alicdn.com/t/font_985780_km7mi63cihi.eot?t=1545807318834#iefix') format('embedded-opentype'),
  30. url('https://at.alicdn.com/t/font_985780_km7mi63cihi.woff?t=1545807318834') format('woff'),
  31. url('https://at.alicdn.com/t/font_985780_km7mi63cihi.ttf?t=1545807318834') format('truetype'),
  32. url('https://at.alicdn.com/t/font_985780_km7mi63cihi.svg?t=1545807318834#iconfont') format('svg');
  33. }
  34. .iconfont {
  35. font-family: "iconfont logo";
  36. font-size: 160px;
  37. font-style: normal;
  38. -webkit-font-smoothing: antialiased;
  39. -moz-osx-font-smoothing: grayscale;
  40. }
  41. /*字体图标结束*/
  42. /*头部布局*/
  43. /*头像*/
  44. header {
  45. height: 50px;
  46. display: flex;
  47. justify-content: space-between;
  48. background-color: #2d353c;
  49. align-items: center;
  50. padding: 0 20px;
  51. }
  52. header > :first-child {
  53. height: 60%;
  54. }
  55. header > :first-child > img {
  56. border-radius: 50%;
  57. height: 100%;
  58. }
  59. header > :nth-child(2) {
  60. height: 100%;
  61. }
  62. header > :nth-child(2) > img {
  63. height: 100%;
  64. }
  65. header > span {
  66. color: white;
  67. }
  68. header > span > .iconfont {
  69. font-size: 30px;
  70. }
  71. /*头部结束*/
  72. /*中部*/
  73. main {
  74. height: calc(100vh - 100px);
  75. display: flex;
  76. overflow: auto;
  77. flex-direction: column;
  78. }
  79. /*banner部分*/
  80. main > .banner {
  81. /*height: 60px;*/
  82. }
  83. main > .banner > a > img {
  84. width: 100%;
  85. }
  86. /*banner部分结束*/
  87. main > .quick-entry {
  88. display: flex;
  89. flex-flow: row wrap;
  90. padding: 15px 0;
  91. background-color: #fff;
  92. margin-bottom: 15px;
  93. flex-shrink: 0;
  94. }
  95. main > .quick-entry > div {
  96. display: flex;
  97. width: 25%;
  98. flex-direction: column;
  99. align-items: center;
  100. justify-content: space-between;
  101. }
  102. main > .quick-entry > div:nth-child(-n+4) {
  103. margin-bottom: 20px;
  104. }
  105. /*快速入口图标部分*/
  106. main > .quick-entry > div > a:first-child {
  107. width: 50%;
  108. }
  109. main > .quick-entry > div > a:first-child > img {
  110. width: 100%;
  111. }
  112. /*快速入口文字部分*/
  113. main > .quick-entry > div > a:last-child {
  114. color: #555555;
  115. }
  116. /*标题*/
  117. main .title {
  118. font-size: 18px;
  119. font-weight: bold;
  120. color: #888888;
  121. padding: 15px;
  122. }
  123. /*推荐课程部分*/
  124. main > .lesson {
  125. display: flex;
  126. flex-direction: column;
  127. flex-shrink: 0;
  128. }
  129. /*广告区*/
  130. main > .lesson > .ads {
  131. display: flex;
  132. justify-content: space-between;
  133. padding: 0 15px 15px 15px;
  134. height: 80px;
  135. }
  136. main > .lesson > .ads > a {
  137. flex-basis: 49%;
  138. }
  139. main > .lesson > .ads > a > img {
  140. width: 100%;
  141. height: 100%;
  142. }
  143. /*课程列表区*/
  144. main > .lesson > .lesson-detail {
  145. display: flex;
  146. background-color: #fff;
  147. margin: 0 15px 15px 15px;
  148. padding: 10px;
  149. height: 80px;
  150. color: #888888;
  151. box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
  152. }
  153. /*左侧图片*/
  154. main > .lesson > .lesson-detail > a {
  155. width: 40%;
  156. }
  157. main > .lesson > .lesson-detail > a > img {
  158. width: 100%;
  159. height: 100%;
  160. }
  161. /*右侧文字*/
  162. main > .lesson > .lesson-detail > div {
  163. padding-left: 15px;
  164. display: flex;
  165. flex-direction: column;
  166. width: 60%;
  167. }
  168. main > .lesson > .lesson-detail > div > a {
  169. color: #888888;
  170. overflow: hidden;
  171. white-space: nowrap;
  172. text-overflow: ellipsis;
  173. }
  174. main > .lesson > .lesson-detail > div > div > :first-child {
  175. background-color: #595757;
  176. color: white;
  177. padding: 0 5px;
  178. border-radius: 10px / 50%;
  179. }
  180. /*最新课程部分*/
  181. main > .lesson > .lesson-detail > .new {
  182. justify-content: space-between;
  183. }
  184. main > .lesson > .lesson-detail > div.new > span {
  185. width: 95%;
  186. overflow: hidden;
  187. white-space: nowrap;
  188. text-overflow: ellipsis;
  189. font-size: 12px;
  190. }
  191. main > .lesson > .lesson-detail > .new > div {
  192. display: flex;
  193. justify-content: space-between;
  194. }
  195. /*最新文章部分*/
  196. main > .lesson > .article {
  197. height: 60px;
  198. }
  199. main > .lesson > .article > a {
  200. order: 2;
  201. }
  202. main > .lesson > .article > div {
  203. order: 1;
  204. padding-left: 0;
  205. }
  206. main > .lesson > .article > div > a {
  207. font-weight: bold;
  208. margin-bottom: 5px;
  209. }
  210. main > .lesson > .article > div > span {
  211. font-size: 12px;
  212. }
  213. /*更多内容*/
  214. main a.more {
  215. text-align: center;
  216. padding: 10px 0;
  217. margin: 0 15px 15px 15px;
  218. background-color: #fff;
  219. color: #888888;
  220. box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
  221. }
  222. /*最新博文*/
  223. main > .blog {
  224. display: flex;
  225. flex-direction: column;
  226. flex-shrink: 0;
  227. }
  228. main > .blog > .blogdetail {
  229. display: flex;
  230. margin: 0 15px 15px 15px;
  231. padding: 15px;
  232. background-color: #fff;
  233. color: #888888;
  234. box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2);
  235. }
  236. main > .blog > .blogdetail > :first-child {
  237. flex: 1;
  238. font-weight: bold;
  239. overflow: hidden;
  240. white-space: nowrap;
  241. text-overflow: ellipsis;
  242. }
  243. main > .blog > .blogdetail > :first-child > a {
  244. color: #888888;
  245. }
  246. main > .blog > .blogdetail > :last-child {
  247. width: 25%;
  248. text-align: right;
  249. }
  250. /*中部结束*/
  251. /*尾部*/
  252. footer {
  253. height: 50px;
  254. background-color: #cccccc;
  255. display: flex;
  256. align-items: center;
  257. }
  258. footer > div {
  259. flex-basis: 25%;
  260. display: flex;
  261. flex-direction: column;
  262. align-items: center;
  263. color: #888888;
  264. }
  265. footer > div.active {
  266. color: lightcoral;
  267. }
  268. footer > div > span > .iconfont {
  269. font-size: 16px;
  270. }

问题

在firefox\chrome下正常,但在360极速浏览器下显示不正常,布局错乱,经查是flex自动收缩导致,把main内所有竖向排列的容器上加上flex-shrink:0后解决。因本页面是为了练习flex所做,所以使用了大量的flex,在实际使用中,个人认为main内的元素还是使用正常布局比较好,包括整个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