博客列表 >flex布局(弹性布局)实战仿PHP中文网手机页面

flex布局(弹性布局)实战仿PHP中文网手机页面

赵大叔
赵大叔原创
2020年04月12日 00:45:00778浏览

效果展示地址:
仿PHP中文网手机页面

flex布局(弹性布局)实战仿PHP中文网手机页面

1.1 头部header: 用户头像、logo 、用户导航,水平排列

1.2 轮播图banner:可点图片a+img

1.3 导航nav:2个无序列表ul垂直排列。每个ul中4个列表li水平排列。li内是可点击a的1张图片img和图片说明span。

1.4 主体main:主体main分为:推荐课程recomment、最新更新rupdate、最新文章article、最新博文blog、最新问答quan五部分垂直排列。

2、html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>m.php.cn</title>
  6. <link rel="stylesheet" href="./css/iconfont.css">
  7. <link rel="stylesheet" href="./css/m.php.cn.css">
  8. </head>
  9. <body>
  10. <header>
  11. <a href=""><img src="./img/profilephoto.jpg" alt=""></a>
  12. <a href=""><img src="./img/logo.png" alt=""></a>
  13. <span class="iconfont"></span>
  14. </header>
  15. <div class="banner">
  16. <a href=""><img src="./img/banner.png" alt=""></a>
  17. </div>
  18. <nav>
  19. <ul>
  20. <li>
  21. <a href="">
  22. <img src="./img/html.png" alt="">
  23. <span>HTML/CSS</span>
  24. </a>
  25. </li>
  26. <li>
  27. <a href="">
  28. <img src="./img/JavaScript.png" alt="">
  29. <span>JavaScript</span>
  30. </a>
  31. </li>
  32. <li>
  33. <a href="">
  34. <img src="./img/code.png" alt="">
  35. <span>服务端</span>
  36. </a>
  37. </li>
  38. <li>
  39. <a href="">
  40. <img src="./img/sql.png" alt="">
  41. <span>数据库</span>
  42. </a>
  43. </li>
  44. </ul>
  45. </nav>
  46. <main>
  47. <article class="recommend">
  48. <h3>推荐课程</h3>
  49. <section>
  50. <a href=""><img src="./img/recom1.jpg" alt=""></a>
  51. <a href=""><img src="./img/recom2.jpg" alt=""></a>
  52. </section>
  53. <section>
  54. <div>
  55. <a href=""><img src="./img/recom3.jpg" alt=""></a>
  56. <span>
  57. <a href="">CI框架30分钟极速入门</a>
  58. <span><i>中级</i>61226次播放</span>
  59. </span>
  60. </div>
  61. </section>
  62. </article>
  63. <article class="update">
  64. <h3>最新更新</h3>
  65. <section>
  66. <div>
  67. <a href=""><img src="./img/up1.png" alt=""></a>
  68. <span>
  69. <a href="">PHP快速操控Excel之PhpSpreadsheet</a>
  70. <span>老的PHPExcel已经停止更新了!目前最新的是使用phpOffice插件PhpSpreadsheet...</span>
  71. <span><i>中级</i>15011次播放</span>
  72. </span>
  73. </div>
  74. </section>
  75. </article>
  76. <article class="article">
  77. <h3>最新文章</h3>
  78. <section>
  79. <span>
  80. <a href="">sublime正则搜索替换修改数据的方法</a>
  81. <span><i>发布时间:</i>2020-04-11</span>
  82. </span>
  83. <a href=""><img src="./img/art1.jpg" alt=""></a>
  84. </section>
  85. <section>
  86. <a href="">更多内容</a>
  87. </section>
  88. </article>
  89. <article class="blog">
  90. <h3>最新博文</h3>
  91. <section>
  92. <span>
  93. Jquery+AJAX上传文件,无刷新上传并重命名文件...
  94. </span>
  95. <i>2020-04-11</i>
  96. </section>
  97. <section>
  98. <a href="">更多内容</a>
  99. </section>
  100. </article>
  101. <article class="questions_answers">
  102. <h3>最新问答</h3>
  103. <section>
  104. <span>
  105. 制定的学习计划在哪能找到 咋找不到呢?
  106. </span>
  107. <i>2020-04-11</i>
  108. </section>
  109. <section>
  110. <a href="">更多内容</a>
  111. </section>
  112. </article>
  113. </main>
  114. <footer>
  115. <div>
  116. <span class="iconfont"></span>
  117. <span>首页</span>
  118. </div>
  119. <div>
  120. <span class="iconfont"></span>
  121. <span>视频</span>
  122. </div>
  123. <div>
  124. <span class="iconfont"></span>
  125. <span>社区</span>
  126. </div>
  127. <div>
  128. <span class="iconfont"></span>
  129. <span>我的</span>
  130. </div>
  131. </footer>
  132. </body>
  133. </html>

3、css代码

  1. body {
  2. width: 768px;
  3. background-color: #EDEFF0;
  4. margin: auto;
  5. }
  6. /*头部样式*/
  7. header{
  8. width: 768px;
  9. height: 50px;
  10. background-color: #444444;
  11. /*转为flex*/
  12. display: flex;
  13. /*两端对齐*/
  14. justify-content: space-between;
  15. /*垂直方向居中排列*/
  16. align-items: center;
  17. position: fixed;
  18. top: 0;
  19. }
  20. /*设置用户头像/用户导航图标大小*/
  21. header > a:first-of-type > img {
  22. width: 30px;
  23. height: 30px;
  24. border-radius: 50%;
  25. margin: 5px 15px;
  26. }
  27. header > a:nth-of-type(2) > img {
  28. width: 90px;
  29. height: 50px;
  30. margin: 5px 15px;
  31. }
  32. header > .iconfont {
  33. color: white;
  34. font-size: 1.5rem;
  35. margin: 5px 15px;
  36. }
  37. /*轮播图*/
  38. .banner {
  39. display: flex;
  40. margin-top: 0;
  41. }
  42. .banner img {
  43. width: 768px;
  44. height: 280px;
  45. }
  46. /*导航区*/
  47. nav {
  48. background-color: #fff;
  49. display: flex;
  50. /*垂直,不换行*/
  51. flex-flow: column nowrap;
  52. }
  53. nav img {
  54. width: 45px;
  55. height: 49px;
  56. }
  57. nav > ul {
  58. display: flex;
  59. }
  60. nav ul li {
  61. flex: 1;
  62. list-style: none;
  63. }
  64. nav ul li a {
  65. display: flex;
  66. flex-flow: column wrap;
  67. align-items: center;
  68. margin: 10px;
  69. }
  70. nav ul li a span {
  71. margin-top: 5px;
  72. align-items: center;
  73. }
  74. /*主体内容区*/
  75. main {
  76. display: flex;
  77. flex-direction: column;
  78. }
  79. /*推荐课程区*/
  80. main > .recommend {
  81. display: flex;
  82. flex-direction: column;
  83. }
  84. main > .recommend > section:first-of-type {
  85. display: flex;
  86. justify-content: space-around;
  87. background-color: #fff;
  88. }
  89. main > .recommend > section:first-of-type img {
  90. width: 368px;
  91. height: 90px;
  92. }
  93. main > .recommend > section:nth-last-of-type(-n+2) div {
  94. display: flex;
  95. }
  96. main > .recommend > section:nth-last-of-type(-n+2) div img {
  97. width: 295px;
  98. height: 83px;
  99. margin: 8px;
  100. }
  101. main > .recommend > section:nth-last-of-type(-n+2) div > span {
  102. display: flex;
  103. flex-direction: column;
  104. margin: 8px;
  105. }
  106. main > .recommend > section:nth-last-of-type(-n+2) div > span > a {
  107. }
  108. main > .recommend > section:nth-last-of-type(-n+2) div > span > span {
  109. margin-top: 8px;
  110. }
  111. main > .recommend > section:nth-last-of-type(-n+2) div > span > span > i {
  112. width: 30px;
  113. height: 24px;
  114. background-color: #444444;
  115. color: white;
  116. border-radius: 10px;
  117. margin-right: 5px;
  118. }
  119. /*最新更新区*/
  120. main > .update {
  121. display: flex;
  122. flex-direction: column;
  123. }
  124. main > .update img {
  125. width: 299px;
  126. height: 82px;
  127. }
  128. main > .update section {
  129. display: flex;
  130. flex-direction: column;
  131. background-color: #fff;
  132. }
  133. main > .update section > div {
  134. height: 102px;
  135. display: flex;
  136. }
  137. main > .update section > div > span {
  138. display: flex;
  139. flex-direction: column;
  140. font-size: 0.8rem;
  141. margin-left: 15px;
  142. }
  143. main > .update section > div > span > span:first-of-type {
  144. margin: 10px auto;
  145. }
  146. main > .update section > div > span > span:last-of-type i {
  147. background-color: #444444;
  148. color: white;
  149. border-radius: 10px;
  150. margin-right: 5px;
  151. }
  152. /*最新文章*/
  153. main > .article img {
  154. width: 222px;
  155. height: 69px;
  156. }
  157. main > .article {
  158. display: flex;
  159. flex-direction: column;
  160. }
  161. main > .article > section {
  162. display: flex;
  163. justify-content: space-between;
  164. background-color: #fff;
  165. }
  166. main > .article > section > span {
  167. display: flex;
  168. flex-direction: column;
  169. justify-content: space-around;
  170. margin-left: 10px;
  171. }
  172. main > .article > section:last-of-type {
  173. align-self: center;
  174. font-size: 1.2rem;
  175. }
  176. /*最新博文*/
  177. main > .blog {
  178. display: flex;
  179. flex-direction: column;
  180. }
  181. main > .blog > section {
  182. display: flex;
  183. justify-content: space-between;
  184. margin: 5px;
  185. background-color: #fff;
  186. }
  187. main > .blog > section:last-of-type {
  188. align-self: center;
  189. font-size: 1.2rem;
  190. }
  191. /*最新问答*/
  192. main > .questions_answers {
  193. display: flex;
  194. flex-direction: column;
  195. }
  196. main > .questions_answers > section {
  197. display: flex;
  198. justify-content: space-between;
  199. margin: 5px;
  200. background-color: #fff;
  201. }
  202. main > .questions_answers > section:last-of-type {
  203. align-self: center;
  204. font-size: 1.2rem;
  205. }
  206. /*尾部*/
  207. footer {
  208. position: fixed;
  209. bottom: 0;
  210. width: 100%;
  211. height:60px;
  212. min-width: 320px;
  213. max-width: 768px;
  214. /*转为flex*/
  215. display: flex;
  216. flex-direction: row;
  217. justify-content: space-between;
  218. align-items: center;
  219. background-color: #fff;
  220. }
  221. footer > div {
  222. display: flex;
  223. flex-direction: column;
  224. /*justify-content: space-around;*/
  225. margin: auto 15px;
  226. align-items: center;
  227. }
  228. footer > div:first-of-type {
  229. font-size: 1.2rem;
  230. color: red;
  231. }

4、总结:

4.1 html标签的正确使用十分重要,使用正确在CSS写样式的时候效果十分明显。

4.2 选择器相关知识必不可少。

4.3 熟能生巧,我第二次写,明显感觉轻松很多,所以一定要多写多看。

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