博客列表 >CSS基础flex实战php中文网移动端首页-PHP培训十期线上班 学号:510251 12月27日作业

CSS基础flex实战php中文网移动端首页-PHP培训十期线上班 学号:510251 12月27日作业

赵大叔
赵大叔原创
2019年12月31日 17:37:22803浏览

flex项目实战php中文网移动端首页

整体实现思路

整个页面分为:头部header、轮播图banner、导航nav 、主体main、尾部footer五大部份。
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、最新更新renew、最新文章article、最新博文blog、最新问答quan五部分垂直排列。


1.5 尾部footer:4个字体图标和说明span水平排列,每个字体图标和说明span垂直排列。


代码

HTML代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>php中文网移动端首页</title>
  6. <link rel="stylesheet" href="static/css/style.css">
  7. </head>
  8. <body>
  9. <header>
  10. <a href=""><img src="static/images/user-pic1.jpg" alt=""></a>
  11. <a href=""><img src="static/images/logo.png" alt=""></a>
  12. <a href=""><img src="static/images/user-nav.jpg" alt=""></a>
  13. </header>
  14. <div class="banner">
  15. <a href=""><img src="static/images/banner.jpg" alt=""></a>
  16. </div>
  17. <nav>
  18. <ul>
  19. <li>
  20. <a href="">
  21. <img src="static/images/html.png" alt="">
  22. <span>HTML/CSS</span>
  23. </a>
  24. </li>
  25. <li>
  26. <a href="">
  27. <img src="static/images/JavaScript.png" alt="">
  28. <span>JavaScript</span>
  29. </a>
  30. </li>
  31. <li>
  32. <a href="">
  33. <img src="static/images/code.png" alt="">
  34. <span>服务器端</span>
  35. </a>
  36. </li>
  37. <li>
  38. <a href="">
  39. <img src="static/images/sql.png" alt="">
  40. <span>数据库</span>
  41. </a>
  42. </li>
  43. </ul>
  44. </nav>
  45. <main>
  46. <article class="recommend">
  47. <h3>推荐课程</h3>
  48. <section>
  49. <a href=""><img src="static/images/tjkc1.jpg" alt=""></a>
  50. <a href=""><img src="static/images/tjkc2.jpg" alt=""></a>
  51. </section>
  52. <section>
  53. <div>
  54. <a href=""><img src="static/images/tjkc3.jpg" alt=""></a>
  55. <span>
  56. <a href="">CI框架30分钟极速入门</a>
  57. <span><i>中级</i>55780次播放</span>
  58. </span>
  59. </div>
  60. </section>
  61. </article>
  62. <article class="renew">
  63. <h3>最新更新</h3>
  64. <section>
  65. <div>
  66. <a href=""><img src="static/images/zxkc1.jpg" alt=""></a>
  67. <span>
  68. <a href="">2019python自学视频</a>
  69. <span>本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带...</span>
  70. <span><i>中级</i>55780次播放</span>
  71. </span>
  72. </div>
  73. </section>
  74. </article>
  75. <article class="article">
  76. <h3>最新文章</h3>
  77. <section>
  78. <div>
  79. <span>
  80. <a href="">java学了做什么?</a>
  81. <span><i>发布时间:</i>2019-12-30</span>
  82. </span>
  83. <a href=""><img src="static/images/zxwz1.jpg" alt=""></a>
  84. </div>
  85. </section>
  86. <section>
  87. <div>
  88. <span>
  89. <a href="">更多内容</a>
  90. </span>
  91. </div>
  92. </section>
  93. </article>
  94. <article class="blog">
  95. <h3>最新博文</h3>
  96. <section>
  97. <span>
  98. composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器...
  99. </span>
  100. <i>2019-12-27</i>
  101. </section>
  102. </article>
  103. <article class="quan">
  104. <h3>最新问答</h3>
  105. <section>
  106. <span>
  107. 变量规则无法定义
  108. </span>
  109. <i>2019-12-30</i>
  110. </section>
  111. </article>
  112. </main>
  113. <footer>
  114. <a href="">
  115. <img src="static/font-icon/zhuye.png" alt="">
  116. <span>首页</span>
  117. </a>
  118. <a href="">
  119. <img src="static/font-icon/video.png" alt="">
  120. <span>视频</span>
  121. </a>
  122. <a href="">
  123. <img src="static/font-icon/luntan.png" alt="">
  124. <span>社区</span>
  125. </a>
  126. <a href="">
  127. <img src="static/font-icon/geren.png" alt="">
  128. <span>我的</span>
  129. </a>
  130. </footer>
  131. </body>
  132. </html>

css代码

  1. @import "reset.css";
  2. /*头部样式*/
  3. header{
  4. /*固定定位*/
  5. position: fixed;
  6. top: 0;
  7. /*宽度自适应*/
  8. width: 100%;
  9. height:45px;
  10. background-color: #444444;
  11. color: #ffffff;
  12. min-width: 320px;
  13. max-width: 768px;
  14. /*转为flex*/
  15. display: flex;
  16. /*水平排列*/
  17. flex-direction: row;
  18. /*两端对齐*/
  19. justify-content: space-between;
  20. /*垂直方向居中排列*/
  21. align-items: center;
  22. }
  23. /*设置用户头像/用户导航图标大小*/
  24. header > a:first-of-type > img,
  25. header > a:last-of-type > img {
  26. width: 30px;
  27. height: 30px;
  28. margin: 5px;
  29. }
  30. header > a:first-of-type > img {
  31. /*用户头像圆角*/
  32. border-radius: 50%;
  33. }
  34. /*轮播图*/
  35. .banner > a {
  36. display: flex;
  37. height: 200px;
  38. }
  39. /*导航区*/
  40. nav {
  41. background-color: #fff;
  42. display: flex;
  43. /*垂直,不换行*/
  44. flex-flow: column nowrap;
  45. }
  46. nav img {
  47. width: 45px;
  48. height: 49px;
  49. }
  50. nav > ul {
  51. display: flex;
  52. }
  53. nav ul li {
  54. flex: 1;
  55. }
  56. nav ul li a {
  57. display: flex;
  58. flex-flow: column wrap;
  59. align-items: center;
  60. margin: 10px;
  61. }
  62. nav ul li a span {
  63. margin-top: 5px;
  64. align-items: center;
  65. }
  66. /*主体内容区*/
  67. main {
  68. display: flex;
  69. flex-direction: column;
  70. }
  71. main > .recommend > section:first-of-type {
  72. /*第1个section内两图片水平排列*/
  73. display: flex;
  74. flex-direction: row;
  75. }
  76. main > .recommend > section:first-of-type > a {
  77. /*第1个section内两图片样式*/
  78. margin: 5px;
  79. flex: 1;
  80. }
  81. main > .recommend > section:first-of-type > a > img {
  82. /*第1个section内两图片高度*/
  83. height: 90px;
  84. }
  85. main > .recommend > section:last-of-type {
  86. /*第2个section内两div(图片和说明)整体垂直排列*/
  87. display: flex;
  88. flex-direction: column;
  89. }
  90. main > .recommend > section:last-of-type > div {
  91. background-color: #fff;
  92. margin: 5px;
  93. display: flex;
  94. /*图片和说明水平排列*/
  95. flex-direction: row;
  96. }
  97. main > .recommend > section:last-of-type > div img {
  98. width: 350px;
  99. height: 90px;
  100. }
  101. main > .recommend > section:last-of-type > div > span {
  102. flex: 1;
  103. display: flex;
  104. /*说明垂直排列*/
  105. flex-direction: column;
  106. margin-top: 5px;
  107. padding-left: 10px;
  108. }
  109. main > .recommend > section:last-of-type > div > span i {
  110. font-style: normal;
  111. background-color: #333333;
  112. color: white;
  113. border-radius: 3px;
  114. padding: 0 5px;
  115. font-size: smaller;
  116. }
  117. main > .recommend > section:last-of-type > div > span > span {
  118. margin-top: 40px;
  119. display: flex;
  120. /*初级、播放次数水平*/
  121. flex-direction: row;
  122. justify-content: space-between;
  123. }
  124. body {
  125. height: 2000px;
  126. }
  127. /*设置最新更新垂直排列*/
  128. main > .renew > {
  129. display: flex;
  130. /*h3\section垂直*/
  131. flex-direction: column;
  132. }
  133. main > .renew > section > {
  134. display: flex;
  135. /div垂直*/
  136. flex-direction: column;
  137. }
  138. main > .renew > section > div {
  139. display: flex;
  140. /*div内图片和span水平*/
  141. flex-direction: row;
  142. margin: 40px 0;
  143. }
  144. main > .renew > section > div > span {
  145. display: flex;
  146. /*span内a\span垂直*/
  147. flex-direction: column;
  148. margin-top: 5px;
  149. margin-left: 5px;
  150. }
  151. main > .renew > section > div > span >span {
  152. margin-top: 5px;
  153. font-size: 14px;
  154. }
  155. main > .renew > section > div > span >span > i {
  156. font-size: 14px;
  157. }
  158. main > .renew > section > div > span i {
  159. font-style: normal;
  160. background-color: #333333;
  161. color: white;
  162. border-radius: 3px;
  163. font-size: smaller;
  164. }
  165. main > .renew > section > div > span > span {
  166. display: flex;
  167. /*初级、播放次数水平*/
  168. flex-direction: row;
  169. justify-content: space-between;
  170. }
  171. main > .renew > section > div img {
  172. width: 300px;
  173. height: 80px;
  174. }
  175. /*最新文章*/
  176. main > .article {
  177. display: flex;
  178. flex-direction: column;
  179. }
  180. main > .article > section > div {
  181. display: flex;
  182. flex-direction: row;
  183. justify-content: space-between;
  184. margin: 5px 0;
  185. background-color: white;
  186. }
  187. main > .article > section > div img {
  188. width: 220px;
  189. height: 70px;
  190. }
  191. main > .article > section > div > span {
  192. display: flex;
  193. flex-direction: column;
  194. margin: 10px 0;
  195. }
  196. /*最新博文*/
  197. main > .blog {
  198. display: flex;
  199. flex-direction: column;
  200. }
  201. main > .blog > section {
  202. display: flex;
  203. flex-direction: row;
  204. background-color: white;
  205. margin: 5px 0;
  206. height: 50px;
  207. justify-content: space-between;
  208. }
  209. main > .blog > section > span {
  210. margin-top: 15px;
  211. }
  212. main > .blog > section > i {
  213. margin-top: 15px;
  214. }
  215. /*最新问答*/
  216. main > .quan {
  217. display: flex;
  218. flex-direction: column;
  219. }
  220. main > .quan > section {
  221. display: flex;
  222. flex-direction: row;
  223. background-color: white;
  224. margin: 5px 0;
  225. height: 50px;
  226. justify-content: space-between;
  227. }
  228. main > .quan > section > span {
  229. margin-top: 15px;
  230. }
  231. main > .quan > section > i {
  232. margin-top: 15px;
  233. }
  234. /*尾部*/
  235. footer {
  236. position: fixed;
  237. bottom: 0;
  238. width: 100%;
  239. height:60px;
  240. /*background-color: #444444;*/
  241. color: #ffffff;
  242. min-width: 320px;
  243. max-width: 768px;
  244. /*转为flex*/
  245. display: flex;
  246. flex-direction: row;
  247. justify-content: space-between;
  248. align-items: center;
  249. }
  250. footer > a > img {
  251. width: 20px;
  252. height: 20px;
  253. margin: 5px;
  254. }
  255. footer > a > span {
  256. display: flex;
  257. flex-direction: column;
  258. color: red;
  259. }

效果图

总结:
第一次没有完全老师代码的作业,过程很艰难。结果不知道合格不合格。但是个人觉得进步很大,感常见蛮有成就感的。

不足之处:就是基础不牢固,需要慢慢补充。

提问老师:布局之外的其它样式,比如宽高,字体……是须要通过不断写代码积累的吗?还是通过什么工具测量的?

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