Blogger Information
Blog 32
fans 0
comment 0
visits 27686
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
flex布局实战-仿PHP中文网手机端首页
Yang_Sir
Original
431 people have browsed it

flex布局实战-仿PHP中文网手机端首页

1.代码说明

  • 只做了首页,没有做其它页面
  • 无js
  • 本页面全部使用flex布局

2.源代码

  • html代码

    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="css/base.css" />
    8. <link rel="stylesheet" href="css/font.css" />
    9. </head>
    10. <body>
    11. <!-- 页眉 -->
    12. <header>
    13. <a href=""> <span class="iconfont">&#xe67c;</span> </a>
    14. <a href=""><img src="images/logo.png" alt="LOGO" /></a>
    15. <a href=""> <span class="iconfont">&#xe65d;</span></a>
    16. </header>
    17. <main>
    18. <!-- 轮播图 -->
    19. <div class="slider">
    20. <a href=""><img src="images/banner2.jpg" alt="banner" /></a>
    21. </div>
    22. <!-- 导航 -->
    23. <nav>
    24. <div>
    25. <a href=""> <span class="iconfont">&#xe632;</span> </a
    26. ><a href="">HTML5</a>
    27. </div>
    28. <div>
    29. <a href=""> <span class="iconfont">&#xe612;</span> </a
    30. ><a href="">CSS</a>
    31. </div>
    32. <div>
    33. <a href=""> <span class="iconfont">&#xe67e;</span> </a
    34. ><a href="">PHP</a>
    35. </div>
    36. <div>
    37. <a href=""> <span class="iconfont">&#xe670;</span> </a
    38. ><a href="">直播</a>
    39. </div>
    40. <div>
    41. <a href=""> <span class="iconfont">&#xe810;</span> </a
    42. ><a href="">JAVASCRIP</a>
    43. </div>
    44. <div>
    45. <a href=""> <span class="iconfont">&#xe609;</span> </a
    46. ><a href="">移动端</a>
    47. </div>
    48. <div>
    49. <a href=""> <span class="iconfont">&#xe898;</span> </a
    50. ><a href="">手册</a>
    51. </div>
    52. <div>
    53. <a href=""> <span class="iconfont">&#xe625;</span> </a
    54. ><a href="">数据库</a>
    55. </div>
    56. </nav>
    57. <!-- 推荐 -->
    58. <section class="recommend">
    59. <h3 class="title">推荐课程</h3>
    60. <div>
    61. <a href=""><img src="images/recommend1.jpg" alt="推荐课程" /></a>
    62. <a href=""><img src="images/recommend2.jpg" alt="推荐课程" /></a>
    63. </div>
    64. <div>
    65. <a href=""><img src="images/recommend3.jpg" alt="推荐课程" /></a>
    66. <a href="">
    67. <h4><p>每日编程小知识,值得拥有</p></h4>
    68. <p><bb class="icon">中级</bb><small>36438次播放</small></p>
    69. </a>
    70. </div>
    71. <div>
    72. <a href=""><img src="images/recommend3.jpg" alt="推荐课程" /></a>
    73. <a href="">
    74. <h4><p>每日编程小知识,值得拥有</p></h4>
    75. <p><bb class="icon">中级</bb><small>36438次播放</small></p>
    76. </a>
    77. </div>
    78. </section>
    79. <!-- 最新更新 -->
    80. <section class="latest-update">
    81. <h3 class="title">最新更新</h3>
    82. <div>
    83. <a href=""><img src="images/recommend3.jpg" alt="最新更新" /></a>
    84. <div>
    85. <h4>
    86. <a
    87. >每日编程小知识,值得拥有;每日编程小知识,值得拥有每日编程小知识,值得拥有</a
    88. >
    89. </h4>
    90. <p>
    91. <small class="desc"
    92. >这是详细介绍,真的是编的。这是详细介绍,真的是编的。</small
    93. >
    94. </p>
    95. <div><bb class="icon">中级</bb><small>36438次播放</small></div>
    96. </div>
    97. </div>
    98. <div>
    99. <a href=""><img src="images/recommend3.jpg" alt="最新更新" /></a>
    100. <div>
    101. <h4><a>每日编程小知识,值得拥有</a></h4>
    102. <p>
    103. <small class="desc"
    104. >这是详细介绍,真的是编的。这是详细介绍,真的是编的。</small
    105. >
    106. </p>
    107. <div><bb class="icon">中级</bb><small>36438次播放</small></div>
    108. </div>
    109. </div>
    110. <div>
    111. <a href=""><img src="images/recommend3.jpg" alt="最新更新" /></a>
    112. <div>
    113. <h4><a>每日编程小知识,值得拥有</a></h4>
    114. <p>
    115. <small class="desc"
    116. >这是详细介绍,真的是编的。这是详细介绍,真的是编的。</small
    117. >
    118. </p>
    119. <div><bb class="icon">中级</bb><small>36438次播放</small></div>
    120. </div>
    121. </div>
    122. <div>
    123. <a href=""><img src="images/recommend3.jpg" alt="最新更新" /></a>
    124. <div>
    125. <h4><a>每日编程小知识,值得拥有</a></h4>
    126. <p>
    127. <small class="desc"
    128. >这是详细介绍,真的是编的。这是详细介绍,真的是编的。这是详细介绍,真的是编的。这是详细介绍,真的是编的。</small
    129. >
    130. </p>
    131. <div><bb class="icon">中级</bb><small>36438次播放</small></div>
    132. </div>
    133. </div>
    134. <div>
    135. <a href=""><img src="images/recommend3.jpg" alt="最新更新" /></a>
    136. <div>
    137. <h4><a>每日编程小知识,值得拥有</a></h4>
    138. <p>
    139. <small class="desc"
    140. >这是详细介绍,真的是编的。这是详细介绍,真的是编的。</small
    141. >
    142. </p>
    143. <div><bb class="icon">中级</bb><small>36438次播放</small></div>
    144. </div>
    145. </div>
    146. </section>
    147. <!-- 最新文章 -->
    148. <section class="latest-article">
    149. <h3 class="title">最新文章</h3>
    150. <div>
    151. <a href="">
    152. <h4><p>文章标题</p></h4>
    153. <p>发布时间:2020-04-11</p>
    154. </a>
    155. <a href=""><img src="images/recommend3.jpg" alt="最新文章" /></a>
    156. </div>
    157. <div>
    158. <a href="">
    159. <h4><p>文章标题</p></h4>
    160. <p>发布时间:2020-04-11</p>
    161. </a>
    162. <a href=""><img src="images/recommend3.jpg" alt="最新文章" /></a>
    163. </div>
    164. <div>
    165. <a href="">
    166. <h4><p>文章标题</p></h4>
    167. <p>发布时间:2020-04-11</p>
    168. </a>
    169. <a href=""><img src="images/recommend3.jpg" alt="最新文章" /></a>
    170. </div>
    171. <div>
    172. <a href="">
    173. <h4><p>文章标题</p></h4>
    174. <p>发布时间:2020-04-11</p>
    175. </a>
    176. <a href=""><img src="images/recommend3.jpg" alt="最新文章" /></a>
    177. </div>
    178. <div>
    179. <a href="">更多内容</a>
    180. </div>
    181. </section>
    182. <!-- 最新博文 -->
    183. <section class="latest-blog">
    184. <h3 class="title">最新博文</h3>
    185. <div>
    186. <h4>
    187. <a href=""
    188. >博文标题博文标题博文标题博文标题题博文标题博文标题博文标博文标题博文标题</a
    189. >
    190. </h4>
    191. <a href="">2020-04-12</a>
    192. </div>
    193. <div>
    194. <h4><a href="">博文标题</a></h4>
    195. <a href="">2020-04-12</a>
    196. </div>
    197. <div>
    198. <h4><a href="">博文标题</a></h4>
    199. <a href="">2020-04-12</a>
    200. </div>
    201. <div>
    202. <h4><a href="">博文标题</a></h4>
    203. <a href="">2020-04-12</a>
    204. </div>
    205. <div>
    206. <h4><a href="">博文标题</a></h4>
    207. <a href="">2020-04-12</a>
    208. </div>
    209. <div>
    210. <a href="">更多内容</a>
    211. </div>
    212. </section>
    213. <!-- 最新问答 -->
    214. <section class="latest-answers">
    215. <h3 class="title">最新问答</h3>
    216. <div>
    217. <h4><a href="">最新问题</a></h4>
    218. <a href="">2020-04-12</a>
    219. </div>
    220. <div>
    221. <h4><a href="">最新问题</a></h4>
    222. <a href="">2020-04-12</a>
    223. </div>
    224. <div>
    225. <h4><a href="">最新问题</a></h4>
    226. <a href="">2020-04-12</a>
    227. </div>
    228. <div>
    229. <h4><a href="">最新问题</a></h4>
    230. <a href="">2020-04-12</a>
    231. </div>
    232. <div>
    233. <h4><a href="">最新问题</a></h4>
    234. <a href="">2020-04-12</a>
    235. </div>
    236. <div>
    237. <a href="">更多内容</a>
    238. </div>
    239. </section>
    240. </main>
    241. <footer>
    242. <a href=""
    243. ><span class="iconfont">&#xe64e;</span>
    244. <p>首页</p></a>
    245. <a href=""
    246. ><span class="iconfont">&#xe60a;</span>
    247. <p>视频</p></a>
    248. <a href=""
    249. ><span class="iconfont">&#xf02a4;</span>
    250. <p>社区</p></a>
    251. <a href=""
    252. ><span class="iconfont">&#xe654;</span>
    253. <p>我的</p></a>
    254. </footer>
    255. </body>
    256. </html>
  • css代码
  1. * {
  2. max-width: 800px;
  3. margin: 0;
  4. padding: 0;
  5. }
  6. html {
  7. overflow-y: scroll;
  8. }
  9. :root {
  10. overflow-y: auto;
  11. overflow-x: hidden;
  12. }
  13. :root body {
  14. position: absolute;
  15. }
  16. body {
  17. width: 100vw;
  18. overflow: hidden;
  19. }
  20. html {
  21. width: 100vh;
  22. height: 100vw;
  23. font-size: 14px;
  24. margin: auto;
  25. }
  26. body {
  27. background-color: rgb(246, 248, 248);
  28. min-width: 320px;
  29. max-width: 800px;
  30. display: flex;
  31. flex-flow: column nowrap;
  32. }
  33. a {
  34. color: rgb(105, 74, 74);
  35. text-decoration: none;
  36. }
  37. a:hover {
  38. color: skyblue;
  39. }
  40. /* 页眉 */
  41. header {
  42. height: 8vh;
  43. background-color: rgb(14, 12, 12);
  44. display: flex;
  45. align-items: center;
  46. justify-content: space-around;
  47. position: fixed;
  48. width: 100vw;
  49. }
  50. header > a:nth-of-type(2) {
  51. width: 60%;
  52. }
  53. header > a:last-of-type {
  54. margin-right: 20px;
  55. }
  56. header > a:nth-of-type(2) > img {
  57. width: 100%;
  58. height: 7vh;
  59. }
  60. header > a > span {
  61. font-size: 1.8rem;
  62. }
  63. /*广告图*/
  64. .slider {
  65. margin-top: 7vh;
  66. display: flex;
  67. justify-content: center;
  68. }
  69. .slider > a > img {
  70. width: 100vw;
  71. height: 140px;
  72. }
  73. /* 导航区 */
  74. nav {
  75. border-top: 1px solid lightgray;
  76. margin: 5px 0;
  77. width: 100vw;
  78. padding: 10px 0px;
  79. height: 140px;
  80. display: flex;
  81. flex-flow: row wrap;
  82. align-content: space-between;
  83. background-color: #fff;
  84. }
  85. nav > div {
  86. width: 25%;
  87. display: flex;
  88. flex-flow: column nowrap;
  89. align-items: center;
  90. }
  91. nav > div .iconfont {
  92. font-size: 3em;
  93. }
  94. /*内容块标题*/
  95. .title {
  96. color: rgb(145, 43, 43);
  97. margin: 10px;
  98. align-self: flex-start;
  99. }
  100. /*主体内容区通用属性设置*/
  101. .latest-update,
  102. .latest-article,
  103. .latest-blog,
  104. .latest-answers,
  105. .recommend {
  106. margin: 5px;
  107. width: 100vw;
  108. border-top: 1px solid #cfcfcf;
  109. display: flex;
  110. flex-flow: column nowrap;
  111. }
  112. .latest-update,
  113. .latest-article,
  114. .latest-blog,
  115. .latest-answers,
  116. .recommend > div {
  117. box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
  118. }
  119. /* 推荐区 */
  120. .recommend > div {
  121. width: 100%;
  122. display: flex;
  123. margin: 5px 0;
  124. justify-content: space-between;
  125. }
  126. .recommend > div > a {
  127. width: 45vw;
  128. padding: 10px;
  129. }
  130. .recommend > div img {
  131. width: 100%;
  132. height: 80px;
  133. }
  134. .recommend > div:first-of-type > a {
  135. padding: 5px;
  136. }
  137. .recommend > div:not(:first-of-type) > a:last-of-type {
  138. display: flex;
  139. flex-flow: column nowrap;
  140. justify-content: space-around;
  141. padding: 10px;
  142. }
  143. /*等级图标*/
  144. .icon {
  145. background-color: #800040;
  146. color: wheat;
  147. border-radius: 30%;
  148. padding: 1px;
  149. font-size: 0.8em;
  150. }
  151. /* 最新更新*/
  152. .latest-update > div {
  153. display: flex;
  154. background-color: #fff;
  155. margin: 5px 0;
  156. }
  157. .latest-update > div > a {
  158. width: 45%;
  159. padding: 10px;
  160. }
  161. .latest-update > div img {
  162. width: 90%;
  163. height: 60px;
  164. }
  165. .latest-update > div > div {
  166. width: 50%;
  167. display: flex;
  168. flex-flow: column nowrap;
  169. justify-content: space-around;
  170. padding: 10px;
  171. padding-right: 30px;
  172. }
  173. .latest-update > div > div > div {
  174. display: flex;
  175. justify-content: space-between;
  176. }
  177. /*最新文章*/
  178. .latest-article > div {
  179. display: flex;
  180. height: 70px;
  181. justify-content: space-between;
  182. background-color: #fff;
  183. margin: 5px 0;
  184. }
  185. .latest-article > div:last-of-type {
  186. height: 25px;
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. }
  191. .latest-article > div > a:first-of-type {
  192. display: flex;
  193. flex-flow: column nowrap;
  194. justify-content: space-around;
  195. align-items: flex-start;
  196. margin-left: 10px;
  197. }
  198. .latest-article > div > a:last-of-type {
  199. display: flex;
  200. align-items: center;
  201. width: 48vw;
  202. }
  203. .latest-article > div > a:last-of-type > img {
  204. width: 80%;
  205. height: 50px;
  206. margin-right: 30px;
  207. }
  208. /*最新博文*/
  209. .latest-blog > div {
  210. display: flex;
  211. height: 32px;
  212. justify-content: space-between;
  213. background-color: #fff;
  214. margin: 5px 0;
  215. padding: 10px;
  216. padding-right: 30px;
  217. align-items: center;
  218. }
  219. .latest-blog > div:last-of-type {
  220. height: 20px;
  221. padding: 0;
  222. display: flex;
  223. justify-content: center;
  224. align-items: center;
  225. }
  226. /*最新问答*/
  227. .latest-answers > div {
  228. display: flex;
  229. height: 32px;
  230. justify-content: space-between;
  231. background-color: #fff;
  232. margin: 5px 0;
  233. padding: 10px;
  234. padding-right: 30px;
  235. align-items: center;
  236. }
  237. .latest-answers > div:last-of-type {
  238. height: 20px;
  239. padding: 0;
  240. display: flex;
  241. justify-content: center;
  242. align-items: center;
  243. }
  244. /*页脚*/
  245. footer {
  246. height: 8vh;
  247. width: 100vw;
  248. background-color: rgba(143, 130, 120, 0.8);
  249. position: fixed;
  250. bottom: 0;
  251. /* padding: 0 10px; */
  252. display: flex;
  253. justify-content: space-around;
  254. align-items: center;
  255. }
  256. /**/
  257. main {
  258. margin-bottom: 8vh;
  259. }
  260. h4 {
  261. white-space: nowrap;
  262. text-overflow: ellipsis;
  263. overflow: hidden;
  264. }
  265. .desc {
  266. display: block;
  267. font-size: 0.7rem;
  268. white-space: nowrap;
  269. text-overflow: ellipsis;
  270. overflow: hidden;
  271. }

3.页面效果展示

  • 顶部

效果图

4.课程总结

  • flex布局规则简单,适应性强
  • 提前做好设计,通用样式用组合选择器能省很多代码
  • 敲代码要细心,如果发现页面效果和设置的不一样,优先检查自己是不是写错了字。(血的教训:width:vh/heigh:vw)
  • 页面配色也是需要学习的方面//尴尬
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!