博客列表 >2019年12月27日 作业 m.php.cn网站的首页布局(Flex实现)

2019年12月27日 作业 m.php.cn网站的首页布局(Flex实现)

L
L原创
2019年12月28日 19:52:40715浏览

m.php.cn网站的首页布局(Flex实现)

效果图


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. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <link rel="stylesheet" href="static/font/iconfont.css" />
  8. <link rel="stylesheet" href="style.css" />
  9. <title>php中文网</title>
  10. </head>
  11. <body>
  12. <!-- 头部 -->
  13. <header>
  14. <a href=""><img src="static/images/login.png" alt="" /></a>
  15. <a href=""><img src="static/images/logo.png" alt="" /></a>
  16. <a href=""><i class="icon iconfont icon-liebiao"></i></a>
  17. </header>
  18. <!-- 主体内容 -->
  19. <main>
  20. <!-- 轮播图 -->
  21. <div class="lbt">
  22. <a href=""><img src="static/images/2.jpg" /></a>
  23. </div>
  24. <!-- 导航区域 -->
  25. <nav>
  26. <a href=""><img src="static/images/html.png" />测试</a>
  27. <a href=""><img src="static/images/code.png" />测试</a>
  28. <a href=""><img src="static/images/app.png" />测试</a>
  29. <a href=""><img src="static/images/html.png" />测试</a>
  30. <a href=""><img src="static/images/html.png" />测试</a>
  31. <a href=""><img src="static/images/html.png" />测试</a>
  32. <a href=""><img src="static/images/html.png" />测试</a>
  33. <a href=""><img src="static/images/html.png" />测试</a>
  34. </nav>
  35. <!-- 推荐课程 -->
  36. <div class="list1">
  37. <h2>推荐课程</h2>
  38. <div class="comment">
  39. <div>
  40. <a href=""><img src="static/images/5d2426f409839992.jpg" alt="" /></a>
  41. <a href=""><img src="static/images/5d2426f409839992.jpg" alt="" /></a>
  42. </div>
  43. <div class="kc">
  44. <a href="">
  45. <img src="static/images/5d2941e265889366.jpg" alt="" />
  46. </a>
  47. <div>
  48. <a href="">CI框架30分钟极速入门</a>
  49. <div>
  50. <span>中级</span>
  51. <span>55667次播放</span>
  52. </div>
  53. </div>
  54. </div>
  55. <div class="kc">
  56. <a href="">
  57. <img src="static/images/5d2941e265889366.jpg" alt="" />
  58. </a>
  59. <div>
  60. <a href="">CI框架30分钟极速入门</a>
  61. <div>
  62. <span>中级</span>
  63. <span>55667次播放</span>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. <!-- 最新更新 -->
  70. <div class="list2">
  71. <h2>最新更新</h2>
  72. <div class="article">
  73. <div>
  74. <a href="">
  75. <img src="static/images/5da6a50535529903.jpg" alt="" />
  76. </a>
  77. <div>
  78. <a href="">CI框架30分钟极速入门</a>
  79. <span>重点介绍了HTML、CSS、web布局前端核心技术,通过视频讲解</span>
  80. <div>
  81. <span>中级</span>
  82. <span>55667次播放</span>
  83. </div>
  84. </div>
  85. </div>
  86. <div>
  87. <a href="">
  88. <img src="static/images/5da6a50535529903.jpg" alt="" />
  89. </a>
  90. <div>
  91. <a href="">CI框架30分钟极速入门</a>
  92. <span>重点介绍了HTML、CSS、web布局前端核心技术,通过视频讲解</span>
  93. <div>
  94. <span>中级</span>
  95. <span>55667次播放</span>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <!-- 最新文章 -->
  102. <div class="list3">
  103. <h2>最新文章</h2>
  104. <div class="article">
  105. <a href="">
  106. <div>
  107. <span>测试</span>
  108. <span>发布时间:2019-12-28</span>
  109. </div>
  110. <img src="static/images/5e06b36a66f32692.jpg" alt="" />
  111. </a>
  112. <a href="">
  113. <div>
  114. <span>测试</span>
  115. <span>发布时间:2019-12-28</span>
  116. </div>
  117. <img src="static/images/5e06b36a66f32692.jpg" alt="" />
  118. </a>
  119. <a href="">
  120. <div>
  121. <span>测试</span>
  122. <span>发布时间:2019-12-28</span>
  123. </div>
  124. <img src="static/images/5e06b36a66f32692.jpg" alt="" />
  125. </a>
  126. </div>
  127. </div>
  128. <!-- 最新博文 -->
  129. <div class="list4">
  130. <h2>最新博文</h2>
  131. <div class="article">
  132. <a href="">
  133. <span>composer安装laravel,nginx服务器路配置解决404问题,</span>
  134. <span>2019-12-27</span>
  135. </a>
  136. <a href="">
  137. <span>composer安装laravel,nginx服务器路配置解决404问题,</span>
  138. <span>2019-12-27</span>
  139. </a>
  140. <a href="">
  141. <span>composer安装laravel,nginx服务器路配置解决404问题,</span>
  142. <span>2019-12-27</span>
  143. </a>
  144. <a href="">
  145. <span>composer安装laravel,nginx服务器路配置解决404问题,</span>
  146. <span>2019-12-27</span>
  147. </a>
  148. </div>
  149. <a href="">更多内容</a>
  150. </div>
  151. <!-- 最新问答 -->
  152. <div class="list5">
  153. <h2>最新问答</h2>
  154. <div class="article">
  155. <a href="">
  156. <span>我写的代码跟您的一样 在浏览器打开的时候为什么是乱码呢</span>
  157. <span>2019-12-27</span>
  158. </a>
  159. <a href="">
  160. <span>我写的代码跟您的一样 在浏览器打开的时候为什么是乱码呢</span>
  161. <span>2019-12-27</span>
  162. </a>
  163. <a href="">
  164. <span>我写的代码跟您的一样 在浏览器打开的时候为什么是乱码呢</span>
  165. <span>2019-12-27</span>
  166. </a>
  167. <a href="">
  168. <span>我写的代码跟您的一样 在浏览器打开的时候为什么是乱码呢</span>
  169. <span>2019-12-27</span>
  170. </a>
  171. </div>
  172. <a href="">更多内容</a>
  173. </div>
  174. </main>
  175. <!-- 脚部 -->
  176. <footer>
  177. <a href=""><i class="icon iconfont icon-shouyeshouye"></i>首页</a>
  178. <a href=""><i class="icon iconfont icon-yunhang"></i>视频</a>
  179. <a href=""><i class="icon iconfont icon-fenzuguanli"></i>社区</a>
  180. <a href=""><i class="icon iconfont icon-huiyuan2"></i>我的</a>
  181. </footer>
  182. </body>
  183. </html>

css样式

  1. /* 导入公共初始化样式 */
  2. @import "public_reset.css";
  3. body {
  4. max-width: 768px;
  5. margin: auto;
  6. }
  7. /* 头部 */
  8. body > header {
  9. position: fixed;
  10. top: 0;
  11. width: 100vw;
  12. max-width: 768px;
  13. height: 5vh;
  14. background-color: #2d353c;
  15. display: flex;
  16. justify-content: space-between;
  17. align-items: center;
  18. padding: 0 1vw;
  19. box-sizing: border-box;
  20. z-index: 999;
  21. }
  22. body > header > a {
  23. color: #ffffff;
  24. display: flex;
  25. }
  26. body > header img {
  27. width: auto;
  28. height: 3vh;
  29. }
  30. body > header > a:nth-of-type(2) img {
  31. height: 5vh;
  32. }
  33. /* 主体内容 */
  34. body > main {
  35. position: relative;
  36. margin: 5vh 0 7vh 0;
  37. display: flex;
  38. flex-direction: column;
  39. }
  40. body > main h2 {
  41. margin-bottom: 2vw;
  42. }
  43. /* 轮播图 */
  44. body > main > .lbt > a {
  45. display: flex;
  46. }
  47. /* 导航区域 */
  48. body > main > nav {
  49. background-color: #fff;
  50. width: 100vw;
  51. margin-bottom: 1vh;
  52. max-width: 768px;
  53. display: flex;
  54. flex-flow: row wrap;
  55. }
  56. body > main > nav > a {
  57. flex-basis: 25vw;
  58. max-width: 192px;
  59. margin: 1vh auto;
  60. align-items: center;
  61. display: flex;
  62. flex-direction: column;
  63. }
  64. body > main > nav > a img {
  65. width: 45px;
  66. height: 45px;
  67. }
  68. /* 推荐课程 */
  69. body > main > .list1 > .comment {
  70. display: flex;
  71. flex-direction: column;
  72. }
  73. body > main > .list1 > .comment > div {
  74. display: flex;
  75. }
  76. body > main > .list1 > .comment > div:nth-of-type(1) {
  77. justify-content: space-around;
  78. }
  79. body > main > .list1 > .comment > .kc > a {
  80. flex-basis: 40vw;
  81. }
  82. body > main > .list1 > .comment > div > a img {
  83. max-width: 380px;
  84. }
  85. body > main > .list1 > .comment > .kc > div {
  86. flex-basis: 50vw;
  87. padding: 0 1vw;
  88. display: flex;
  89. flex-direction: column;
  90. justify-content: space-around;
  91. }
  92. body > main > .list1 > .comment > .kc {
  93. display: flex;
  94. padding: 1vw;
  95. background-color: #fff;
  96. margin-bottom: 1vh;
  97. justify-content: space-around;
  98. }
  99. body > main > .list1 > .comment > .kc > div > div > span:first-of-type {
  100. background-color: #2d353c;
  101. color: #fff;
  102. padding: 0.4vw;
  103. border-radius: 1vw;
  104. }
  105. /* 最新更新 */
  106. body > main > .list2 > .article > div {
  107. display: flex;
  108. justify-content: space-around;
  109. background-color: #fff;
  110. padding: 1vw;
  111. margin-bottom: 1vw;
  112. }
  113. body > main > .list2 > .article > div > a {
  114. flex-basis: 40vw;
  115. }
  116. body > main > .list2 > .article > div > div {
  117. flex-basis: 50vw;
  118. padding: 0.4vw;
  119. display: flex;
  120. flex-direction: column;
  121. justify-content: space-between;
  122. }
  123. body > main > .list2 > .article > div > div > span {
  124. width: 50vw;
  125. max-width: 380px;
  126. overflow: hidden;
  127. text-overflow: ellipsis;
  128. white-space: nowrap;
  129. }
  130. body > main > .list2 > .article > div > div > div > span:nth-of-type(1) {
  131. background-color: #2d353c;
  132. color: #fff;
  133. padding: 0.4vw;
  134. border-radius: 1vw;
  135. }
  136. body > main > .list2 > .article > div > div > div {
  137. display: flex;
  138. justify-content: space-between;
  139. }
  140. /* 最新文章 */
  141. body > main > .list3 > .article {
  142. display: flex;
  143. flex-direction: column;
  144. justify-content: space-around;
  145. }
  146. body > main > .list3 > .article > a {
  147. display: flex;
  148. justify-content: space-around;
  149. background-color: #fff;
  150. padding: 0.4vw;
  151. margin-bottom: 1vw;
  152. box-shadow: 0 0 8px #cccccc;
  153. }
  154. body > main > .list3 > .article > a > div {
  155. flex-basis: 70vw;
  156. display: flex;
  157. flex-direction: column;
  158. justify-content: space-around;
  159. padding: 0.4vw 1vw;
  160. }
  161. body > main > .list3 > .article > a > img {
  162. flex-basis: 30vw;
  163. max-width: 180px;
  164. }
  165. /* 最新博文 */
  166. body > main > .list4 > .article {
  167. display: flex;
  168. flex-direction: column;
  169. justify-content: space-around;
  170. }
  171. body > main > .list4 > .article > a {
  172. display: flex;
  173. justify-content: space-between;
  174. background-color: #fff;
  175. padding: 0.4vw 1vw;
  176. margin-bottom: 1vw;
  177. align-items: center;
  178. box-shadow: 0 0 8px #cccccc;
  179. }
  180. body > main > .list4 > .article > a > span {
  181. flex-basis: 50vw;
  182. max-width: 380px;
  183. }
  184. body > main > .list4 > .article > a > span:last-of-type {
  185. text-align: right;
  186. }
  187. body > main > .list4 > a {
  188. display: block;
  189. background-color: #fff;
  190. text-align: center;
  191. padding: 0.4vw 1vw;
  192. }
  193. /* 最新问答 */
  194. body > main > .list5 > .article {
  195. display: flex;
  196. flex-direction: column;
  197. justify-content: space-around;
  198. }
  199. body > main > .list5 > .article > a {
  200. display: flex;
  201. justify-content: space-between;
  202. background-color: #fff;
  203. padding: 0.4vw 1vw;
  204. margin-bottom: 1vw;
  205. align-items: center;
  206. box-shadow: 0 0 8px #cccccc;
  207. }
  208. body > main > .list5 > a {
  209. display: block;
  210. background-color: #fff;
  211. text-align: center;
  212. padding: 0.4vw 1vw;
  213. }
  214. body > main > .list5 > .article > a > span {
  215. flex-basis: 50vw;
  216. max-width: 380px;
  217. }
  218. body > main > .list5 > .article > a > span:last-of-type {
  219. text-align: right;
  220. }
  221. /* 脚部 */
  222. body > footer {
  223. width: 100vw;
  224. max-width: 768px;
  225. margin: auto;
  226. position: fixed;
  227. bottom: 0;
  228. height: 6vh;
  229. background-color: #edeff0;
  230. display: flex;
  231. justify-content: space-around;
  232. margin-top: 2vh;
  233. border-top: 1px solid #ccc;
  234. z-index: 999;
  235. }
  236. body > footer > a {
  237. display: flex;
  238. flex-direction: column;
  239. justify-content: center;
  240. align-items: center;
  241. }

公共初始化样式

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. body {
  6. color: #333;
  7. background-color: #edeff0;
  8. }
  9. a {
  10. color: #333;
  11. text-decoration: none;
  12. }
  13. li {
  14. list-style: none;
  15. }
  16. img {
  17. width: 100%;
  18. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议
L2019-12-30 11:31:001楼
嗯呢,自己写,可以高度自定义,多练习,可以更熟练