博客列表 >flex实战

flex实战

xiaosheng
xiaosheng原创
2019年12月30日 14:42:54915浏览

总结:

1 . flex布局确实比普通布局好用些,但是这对应着,在写之前需要构思好,特别是在横向布局和纵向布局交叉使用的时候,其实写多了也是其中也是有规律可循的

2 . 布局的时候使用定位比flex更直接,但是个人感觉定位如果页面大小不变的话还很不错,如果需要适配移动端或者窗口大小变化的话,这个时候flex反而更直接些

3 . 写之前一定要做好充分的准备工作,否则在写样式的时候,不仅思路会慢慢的混乱,同时代码也会出现大量的冗余

页面效果如下

页面主体

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>php中文网-教程</title>
  6. <link rel="stylesheet" href="./static/font/iconfont.css">
  7. </head>
  8. <body>
  9. <header>
  10. <img src="./images/ia_100000000.jpg" alt="">
  11. <div class="logo">
  12. <img src="./images/ia_100000001.png" alt="">
  13. </div>
  14. <div class="setting">
  15. <i class="iconfont icon-yingyongguanli"></i>
  16. </div>
  17. </header>
  18. <div class="lunbo">
  19. <img src="./images/ia_100000002.png" alt="">
  20. </div>
  21. <div class="nav">
  22. <div class="option">
  23. <div>
  24. <img src="./images/ia_100000006.png" alt="" class="icon">
  25. </div>
  26. <span>HTML/CSS</span>
  27. </div>
  28. <div class="option">
  29. <div>
  30. <img src="./images/ia_100000007.png" alt="" class="icon">
  31. </div>
  32. <span>JavaScript</span>
  33. </div>
  34. <div class="option">
  35. <div>
  36. <img src="./images/ia_100000008.png" alt="" class="icon">
  37. </div>
  38. <span>服务端</span>
  39. </div>
  40. <div class="option">
  41. <div>
  42. <img src="./images/ia_100000009.png" alt="" class="icon">
  43. </div>
  44. <span>数据库</span>
  45. </div>
  46. <div class="option">
  47. <div>
  48. <img src="./images/ia_100000010.png" alt="" class="icon">
  49. </div>
  50. <span>移动端</span>
  51. </div>
  52. <div class="option">
  53. <div>
  54. <img src="./images/ia_100000011.png" alt="" class="icon">
  55. </div>
  56. <span>手册</span>
  57. </div>
  58. <div class="option">
  59. <div>
  60. <img src="./images/ia_100000012.png" alt="" class="icon">
  61. </div>
  62. <span>工具</span>
  63. </div>
  64. <div class="option">
  65. <div>
  66. <img src="./images/ia_100000013.png" alt="" class="icon">
  67. </div>
  68. <span>直播</span>
  69. </div>
  70. </div>
  71. <div class="content">
  72. <span>推荐课程</span>
  73. <div class="courses">
  74. <div class="course1">
  75. <img src="./images/ia_100000014.jpg" alt="">
  76. <img src="./images/ia_100000015.jpg" alt="">
  77. </div>
  78. <div class="course2">
  79. <img src="./images/ia_100000016.jpg" alt="">
  80. <div>
  81. <span class="title">CI框架30分钟极速入门</span>
  82. <span class="level">中级</span>
  83. <span class="times">55748次播放</span>
  84. </div>
  85. </div>
  86. <div class="course2">
  87. <img src="./images/ia_100000017.jpg" alt="">
  88. <div>
  89. <span class="title">2018前端入门_HTML5</span>
  90. <span class="level">初级</span>
  91. <span class="times">257922次播放</span>
  92. </div>
  93. </div>
  94. </div>
  95. <span>最新更新</span>
  96. <div class="update">
  97. <div class="clear-mt update1 course2">
  98. <img src="./images/ia_100000018.jpg" alt="">
  99. <div>
  100. <span class="title">2019python自学视频</span>
  101. <span class="introduce">本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你...</span>
  102. <span class="level">初级</span>
  103. <span class="times times-right">257922次播放</span>
  104. </div>
  105. </div>
  106. <div class=" clear-mtupdate1 course2">
  107. <img src="./images/ia_100000018.jpg" alt="">
  108. <div>
  109. <span class="title">2019python自学视频</span>
  110. <span class="introduce">本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你...</span>
  111. <span class="level">初级</span>
  112. <span class="times times-right">257922次播放</span>
  113. </div>
  114. </div>
  115. <div class="clear-mt update1 course2">
  116. <img src="./images/ia_100000018.jpg" alt="">
  117. <div>
  118. <span class="title">2019python自学视频</span>
  119. <span class="introduce">本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你...</span>
  120. <span class="level">初级</span>
  121. <span class="times times-right">257922次播放</span>
  122. </div>
  123. </div>
  124. <div class="clear-mt update1 course2">
  125. <img src="./images/ia_100000018.jpg" alt="">
  126. <div>
  127. <span class="title">2019python自学视频</span>
  128. <span class="introduce">本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你...</span>
  129. <span class="level">初级</span>
  130. <span class="times times-right">257922次播放</span>
  131. </div>
  132. </div>
  133. <div class="clear-mt update1 course2">
  134. <img src="./images/ia_100000018.jpg" alt="">
  135. <div>
  136. <span class="title">2019python自学视频</span>
  137. <span class="introduce">本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你...</span>
  138. <span class="level">初级</span>
  139. <span class="times times-right">257922次播放</span>
  140. </div>
  141. </div>
  142. <div class="clear-mt update1 course2">
  143. <img src="./images/ia_100000018.jpg" alt="">
  144. <div>
  145. <span class="title">2019python自学视频</span>
  146. <span class="introduce">本课程适合想从零开始学习 Python 编程语言的开发人员。由浅入深的带你...</span>
  147. <span class="level">初级</span>
  148. <span class="times times-right">257922次播放</span>
  149. </div>
  150. </div>
  151. </div>
  152. <span>最新文章</span>
  153. <div class="articles">
  154. <div class="clear-mt article1 course2">
  155. <div>
  156. <span class="title">怎么在linux下载文件</span>
  157. <span class="times">发布时间:</span>
  158. <span class="times">2019-12-30</span>
  159. </div>
  160. <img src="./images/ia_100000024.jpg" alt="">
  161. </div>
  162. <div class="clear-mt article1 course2">
  163. <div>
  164. <span class="title">怎么在linux下载文件</span>
  165. <span class="times">发布时间:</span>
  166. <span class="times">2019-12-30</span>
  167. </div>
  168. <img src="./images/ia_100000024.jpg" alt="">
  169. </div>
  170. <div class="clear-mt article1 course2">
  171. <div>
  172. <span class="title">怎么在linux下载文件</span>
  173. <span class="times">发布时间:</span>
  174. <span class="times">2019-12-30</span>
  175. </div>
  176. <img src="./images/ia_100000024.jpg" alt="">
  177. </div>
  178. <div class="clear-mt article1 course2">
  179. <div>
  180. <span class="title">怎么在linux下载文件</span>
  181. <span class="times">发布时间:</span>
  182. <span class="times">2019-12-30</span>
  183. </div>
  184. <img src="./images/ia_100000024.jpg" alt="">
  185. </div>
  186. <div class="clear-mt article1 course2">
  187. <div>
  188. <span class="title">怎么在linux下载文件</span>
  189. <span class="times">发布时间:</span>
  190. <span class="times">2019-12-30</span>
  191. </div>
  192. <img src="./images/ia_100000024.jpg" alt="">
  193. </div>
  194. </div>
  195. <div class="more">更多内容</div>
  196. <span>最新博文</span>
  197. <div class="blogs">
  198. <div class="blog">
  199. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器...</span>
  200. <span>2019-12-27</span>
  201. </div>
  202. <div class="blog">
  203. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器...</span>
  204. <span>2019-12-27</span>
  205. </div>
  206. <div class="blog">
  207. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器...</span>
  208. <span>2019-12-27</span>
  209. </div>
  210. <div class="blog">
  211. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器...</span>
  212. <span>2019-12-27</span>
  213. </div>
  214. </div>
  215. <div class="more">更多内容</div>
  216. <span>最新问答</span>
  217. <div class="replys blogs">
  218. <div class="blog">
  219. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器 -</span>
  220. <span>2019-12-27</span>
  221. </div>
  222. <div class="blog">
  223. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器 -</span>
  224. <span>2019-12-27</span>
  225. </div>
  226. <div class="blog">
  227. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器 -</span>
  228. <span>2019-12-27</span>
  229. </div>
  230. <div class="blog">
  231. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器 -</span>
  232. <span>2019-12-27</span>
  233. </div>
  234. <div class="blog">
  235. <span>composer安装laravel,nginx服务器路配置解决404问题,创建简单的控制器 -</span>
  236. <span>2019-12-27</span>
  237. </div>
  238. </div>
  239. <div class="more">更多内容</div>
  240. </div>
  241. <footer>
  242. <div>
  243. <i class="iconfont icon-daohangshouye"></i>
  244. <span>首页</span>
  245. </div>
  246. <div>
  247. <i class="iconfont icon-daohangshouye"></i>
  248. <span>首页</span>
  249. </div>
  250. <div>
  251. <i class="iconfont icon-daohangshouye"></i>
  252. <span>首页</span>
  253. </div>
  254. <div>
  255. <i class="iconfont icon-daohangshouye"></i>
  256. <span>首页</span>
  257. </div>
  258. </footer>
  259. </body>
  260. </html>

CSS样式

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. body {
  6. width: 768px;
  7. margin: 0 auto;
  8. background-color: #cccccc;
  9. }
  10. header {
  11. width: 768px;
  12. height: 45px;
  13. background-color: RGB(47, 53, 60);
  14. padding: 0 10px;
  15. box-sizing: border-box;
  16. display: flex;
  17. justify-content: space-between;
  18. align-items: center;
  19. position: fixed;
  20. top: 0;
  21. z-index: 999;
  22. }
  23. header > img {
  24. width: 23px;
  25. height: 23px;
  26. border-radius: 50%;
  27. }
  28. header > .logo > img {
  29. width: 95px;
  30. height: 45px;
  31. }
  32. header > .setting > i {
  33. font-size: 19px;
  34. color: #ffffff;
  35. }
  36. .lunbo > img {
  37. margin-top: 45px;
  38. width: 768px;
  39. height: 150px;
  40. }
  41. .nav {
  42. width: 768px;
  43. height: 170px;
  44. background-color: #fff;
  45. padding-top: 5px;
  46. -webkit-box-sizing: border-box;
  47. -moz-box-sizing: border-box;
  48. box-sizing: border-box;
  49. display: flex;
  50. flex-wrap: wrap;
  51. }
  52. .nav > .option {
  53. width: 192px;
  54. height: 75px;
  55. display: flex;
  56. justify-content: center;
  57. align-content: center;
  58. position: relative;
  59. flex-wrap: wrap;
  60. }
  61. .nav > .option > div {
  62. height: 45px;
  63. flex-basis: 192px;
  64. display: flex;
  65. justify-content: center;
  66. }
  67. .nav > .option > div > img {
  68. width: 45px;
  69. height: 45px;
  70. }
  71. .nav > .option > span {
  72. font-size: 14px;
  73. color: rgb(120,120,120);
  74. }
  75. .content {
  76. width: 748px;
  77. margin: 30px auto 75px auto;
  78. }
  79. .content > span {
  80. display: block;
  81. width: 748px;
  82. height: 30px;
  83. font-size: 18px;
  84. color: rgb(135,135,135);
  85. }
  86. .content > .courses {
  87. width: 748px;
  88. height: 371px;
  89. }
  90. .content > .courses > .course1 {
  91. display: flex;
  92. justify-content: space-between;
  93. }
  94. .content > .courses > .course1 > img {
  95. width: 366.5px;
  96. height: 90px;
  97. }
  98. .course2 {
  99. width: 728px;
  100. height: 80px;
  101. background-color: #fff;
  102. padding: 10px;
  103. margin-top: 25px;
  104. display: flex;
  105. }
  106. .course2 > img {
  107. width: 295.1px;
  108. height: 80px;
  109. }
  110. .course2 > div {
  111. width: 405px;
  112. display: flex;
  113. flex-wrap: wrap;
  114. margin-left: 5px;
  115. }
  116. .course2 > div > .title {
  117. width: 410px;
  118. height: 23px;
  119. font-size: 16.5px;
  120. color: rgb(135,135,135);
  121. }
  122. .course2 > div > .level {
  123. height: 20px;
  124. line-height: 20px;
  125. padding: 0 5px;
  126. -webkit-box-sizing: border-box;
  127. -moz-box-sizing: border-box;
  128. box-sizing: border-box;
  129. font-size: 12px;
  130. color: rgb(255,255,255);
  131. background-color: rgb(89,87,87);
  132. border-radius: 8px;
  133. }
  134. .course2 > div > .times {
  135. height: 20px;
  136. line-height: 20px;
  137. font-size: 12px;
  138. color: rgb(135,135,135);
  139. }
  140. .content > .update > .update1 > div {
  141. justify-content: space-between;
  142. align-content: space-between;
  143. }
  144. .clear-mt {
  145. margin: 0 0 25px 0;
  146. }
  147. .content > .update > .update1 > div > .introduce {
  148. font-size: 12px;
  149. color: rgb(135,135,135);
  150. width: 410px;
  151. }
  152. .content > .update > .update1 > div > .times-right {
  153. margin-right: 0;
  154. }
  155. .content > .articles {
  156. height: 536px;
  157. }
  158. .content > .articles > .course2 {
  159. justify-content: space-between;
  160. }
  161. .content > .articles > .article1 > img {
  162. width: 218.3px;
  163. height: 65px;
  164. }
  165. .content .more {
  166. width: 748px;
  167. height: 30px;
  168. line-height: 30px;
  169. font-size: 14px;
  170. margin: 10px 0 25px 0;
  171. text-align: center;
  172. background-color: #fff;
  173. color: rgb(120,120,120);
  174. }
  175. .content > .articles > .clear-mt {
  176. margin: 0 0 10px 0;
  177. }
  178. .content > .blogs > .blog {
  179. width: 748px;
  180. height: 40px;
  181. background-color: #fff;
  182. display: flex;
  183. justify-content: space-between;
  184. padding: 5px 5px 10px 5px;
  185. box-sizing: border-box;
  186. color: rgb(120,120,120);
  187. font-size: 14px;
  188. margin-bottom: 10px;
  189. }
  190. footer {
  191. width: 768px;
  192. height: 50px;
  193. padding-top: 5px;
  194. box-sizing: border-box;
  195. border-top: 1px solid rgb(120,120,120);
  196. display: flex;
  197. justify-content: space-around;
  198. position: fixed;
  199. bottom: 0;
  200. background-color: #cccccc;
  201. z-index: 100;
  202. }
  203. footer > div {
  204. width: 192px;
  205. height: 40px;
  206. display: flex;
  207. flex-direction: column;
  208. justify-content: center;
  209. align-items: center;
  210. font-size: 14px;
  211. color: rgb(120,120,120);
  212. }
  213. footer > div:first-child{
  214. color: red;
  215. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议