Blogger Information
Blog 43
fans 4
comment 0
visits 19426
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
用grid和flex布局完成php中文网首页上半部分
汇享科技
Original
464 people have browsed it

思路分享

效果图:
l5m29h2r.png

  1. 先从顶部开始一部分一部分往下写
  2. 布局方式:分析这一部分可以拆分成几部分 进行构思 用网格来表示看下可以生成几行几列的网格 例如:l5m1lqgj.png
  3. 先写一个大盒子包住 然后在盒子内进行布局 把每块想象成一个盒子左中右三部分
  4. 细致划分里面的区域左边的盒子可以用flex也可以用grid进行划分用flex的话可以将排列方式改为列column然后在给里面的每个标签设置一些边距撑开

代码下载

  • html代码部分
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>仿phpcn首页</title>
  8. <link rel="stylesheet" href="static/css/font.css" />
  9. <link rel="stylesheet" href="static/css/header.css" />
  10. </head>
  11. <body>
  12. <!-- 顶部 -->
  13. <header>
  14. <div class="content">
  15. <div class="top_content">
  16. <div class="title">
  17. <span>php中文网,程序员梦开始的地方</span>
  18. </div>
  19. <div class="right">
  20. <a href="" class="iconfont icon-tixing"></a>
  21. <a href=""><img src="static/images/tx.jpg" alt="" /></a>
  22. </div>
  23. </div>
  24. </div>
  25. </header>
  26. <!-- 导航栏 -->
  27. <nav>
  28. <div class="nav_content">
  29. <div class="logo">
  30. <a href=""><img src="static/images/logo.png" alt="" /></a>
  31. </div>
  32. <div class="navs">
  33. <a href="" class="active">首页</a>
  34. <a href="">视频教程</a>
  35. <a href="">学习路径</a>
  36. <a href="">PHP培训</a>
  37. <a href="">资源下载 </a>
  38. <a href="">技术文章</a>
  39. <a href="">社区</a>
  40. </div>
  41. <div class="nav_right">
  42. <input type="search" name="" id="" placeholder="输入关键字搜索" />
  43. <span class="iconfont icon-sousuo"></span>
  44. </div>
  45. </div>
  46. </nav>
  47. <!-- 主体 -->
  48. <main>
  49. <div class="main_content">
  50. <div class="left">
  51. <a href="">视频教程</a>
  52. <a href="">学习路径</a>
  53. <a href="">PHP培训</a>
  54. <a href="">资源下载 </a>
  55. <a href="">技术文章</a>
  56. <a href="">资源下载 </a>
  57. <a href="">技术文章</a>
  58. <a href="">资源下载 </a>
  59. </div>
  60. <div class="lb">
  61. <a href="">
  62. <img src="static/images/lb.png" alt="" />
  63. </a>
  64. </div>
  65. <div class="right">
  66. <div class="right_top">
  67. <div class="tx">
  68. <span>
  69. <a href="">
  70. <img src="static/images/tx.jpg" alt="" />
  71. </a>
  72. </span>
  73. <dl>
  74. <dt>
  75. <a href="">汇享科技</a>
  76. <span class="iconfont icon-tipvip vip"></span>
  77. </dt>
  78. <dd>P豆 12.00</dd>
  79. </dl>
  80. </div>
  81. <div class="anniu">
  82. <button>我的学习</button>
  83. </div>
  84. </div>
  85. <div class="right_bottom">
  86. <div class="top">
  87. <p class="cont1">
  88. <span>问答社区</span>
  89. <a>答疑</a>
  90. </p>
  91. </div>
  92. <div class="bottom">
  93. <p class="cont2">
  94. <span>头条</span>
  95. <a href="">20期PHP线上班</a>
  96. </p>
  97. <p class="cont3">
  98. <span>福利</span>
  99. <a href="">20期PHP线上班</a>
  100. </p>
  101. <p class="cont3">
  102. <span>新班</span>
  103. <a href="">20期PHP线上班</a>
  104. </p>
  105. <p class="cont3">
  106. <span>招募</span>
  107. <a href="">20期PHP线上班</a>
  108. </p>
  109. <p class="cont3">
  110. <span>公告</span>
  111. <a href="">20期PHP线上班</a>
  112. </p>
  113. </div>
  114. </div>
  115. </div>
  116. <div class="main_bottom">
  117. <div class="bottom_left">
  118. <div class="left_xxlj">
  119. <span>学习路径</span>
  120. <span>全部7个></span>
  121. </div>
  122. <a href="">
  123. <img src="static/images/dgjj.png" alt="" />
  124. <dl>
  125. <dt>独孤九贱</dt>
  126. <dd>9门课程</dd>
  127. </dl>
  128. </a>
  129. <a href="">
  130. <img src="static/images/ynxj.png" alt="" />
  131. <dl>
  132. <dt>玉女心经</dt>
  133. <dd>5门课程</dd>
  134. </dl>
  135. </a>
  136. <a href="">
  137. <img src="static/images/tlbb.png" alt="" />
  138. <dl>
  139. <dt>天龙八部</dt>
  140. <dd>3门课程</dd>
  141. </dl>
  142. </a>
  143. <a href="">
  144. <img src="static/images/phpkjkf.png" alt="" />
  145. <dl>
  146. <dt>自学指南</dt>
  147. <dd>19门课程</dd>
  148. </dl>
  149. </a>
  150. <a href="">
  151. <img src="static/images/phpksrm.png" alt="" />
  152. <dl>
  153. <dt>趣味闯关</dt>
  154. <dd>22门课程</dd>
  155. </dl>
  156. </a>
  157. </div>
  158. </div>
  159. <div class="bottom_right">
  160. <a href="">
  161. <span class="iconfont icon-weixin"></span>
  162. <h2>微信公众号</h2>
  163. </a>
  164. <a href="">
  165. <span class="iconfont icon-QQ-circle-fill"></span>
  166. <h2>官方QQ群</h2>
  167. </a>
  168. </div>
  169. </div>
  170. </main>
  171. </body>
  172. </html>
  • css部分
  1. /*这一部分是初始化样式*/
  2. * {
  3. padding: 0;
  4. margin: 0;
  5. box-sizing: border-box;
  6. }
  7. a {
  8. text-decoration: none;
  9. }
  10. ul {
  11. list-style: none;
  12. }
  13. /*初始化结束*/
  14. /*css代码*/
  15. @import url(init.css);
  16. @import url(font_icon/iconfont.css);
  17. body {
  18. background-color: #f3f5f7;
  19. }
  20. /*顶部布局开始*/
  21. header .content {
  22. width: 100vw;
  23. height: 40px;
  24. background-color: #343434;
  25. }
  26. header .content .top_content {
  27. width: 1200px;
  28. display: grid;
  29. grid-template-columns: 400px 100px;
  30. grid-template-rows: 40px;
  31. margin: auto;
  32. place-content: space-between;
  33. place-items: center start;
  34. }
  35. header .content .top_content .title span {
  36. color: #ccc;
  37. font-weight: 550;
  38. font-family: "微软雅黑";
  39. font-size: 14px;
  40. }
  41. header .content .top_content .right {
  42. display: flex;
  43. place-items: center;
  44. }
  45. header .content .top_content .right img {
  46. border-radius: 30px;
  47. width: 25px;
  48. height: 25px;
  49. margin-left: 22px;
  50. }
  51. header .content .top_content .right .icon-tixing {
  52. font-size: 20px;
  53. color: #fff;
  54. }
  55. /*顶部布局结束*/
  56. /*顶部导航开始*/
  57. nav {
  58. width: 100vw;
  59. height: 90px;
  60. background-color: white;
  61. box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  62. }
  63. nav .nav_content {
  64. width: 1200px;
  65. display: grid;
  66. margin: auto;
  67. gap: 0 10px;
  68. grid-template-columns: 200px 1fr 200px;
  69. grid-auto-rows: 90px;
  70. place-items: center start;
  71. }
  72. nav .nav_content .navs a {
  73. color: #333333;
  74. padding: 0 10px;
  75. font-weight: bold;
  76. }
  77. nav .nav_content .navs .active,
  78. nav .nav_content .navs a:hover {
  79. color: red;
  80. font-size: 18px;
  81. }
  82. nav .nav_right {
  83. display: flex;
  84. }
  85. nav .nav_right input[type="search"] {
  86. width: 200px;
  87. height: 36px;
  88. border: none;
  89. outline: none;
  90. background-color: rgba(219, 211, 211, 0.938);
  91. border-radius: 20px;
  92. padding: 15px;
  93. }
  94. nav .nav_right .icon-sousuo {
  95. position: relative;
  96. left: -30px;
  97. top: 8px;
  98. }
  99. nav .nav_right .icon-sousuo:hover {
  100. color: red;
  101. }
  102. /*导航结束*/
  103. /*主体区开始*/
  104. main {
  105. width: 100%;
  106. margin-top: 30px;
  107. }
  108. main .main_content {
  109. width: 1200px;
  110. margin: auto;
  111. display: grid;
  112. grid-template-columns: 166px 810px 190px;
  113. grid-template-rows: 400px 80px;
  114. gap: 15px;
  115. }
  116. main .main_content .main_bottom {
  117. grid-area: 2 / 1 / span 2 / span 2;
  118. }
  119. main .main_content .left {
  120. border-radius: 20px;
  121. background-color: #fff;
  122. display: flex;
  123. flex-flow: column;
  124. place-items: center;
  125. }
  126. main .main_content .left a {
  127. color: #333333;
  128. width: 126px;
  129. height: 40px;
  130. margin-top: 8px;
  131. padding: 10px 0;
  132. text-align: center;
  133. border-radius: 20px;
  134. }
  135. main .main_content .left a:hover {
  136. background-color: lightsalmon;
  137. }
  138. main .main_content .lb a img {
  139. border-radius: 20px;
  140. width: 100%;
  141. }
  142. main .main_content .right {
  143. /* height: 400px; */
  144. display: grid;
  145. background-color: #fff;
  146. border-radius: 20px;
  147. grid-template-rows: 141px 1fr;
  148. }
  149. main .main_content .right .right_top {
  150. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  151. }
  152. main .main_content .right .right_top .tx {
  153. padding: 18px 0;
  154. width: 155px;
  155. display: grid;
  156. margin: auto;
  157. place-items: center start;
  158. gap: 0 10px;
  159. grid-template-columns: 40px 105px;
  160. }
  161. main .main_content .right .right_top .tx a img {
  162. border-radius: 30px;
  163. width: 100%;
  164. }
  165. main .main_content .right .right_top .tx dl dt > a {
  166. color: #333333;
  167. font-size: 14px;
  168. font-weight: bold;
  169. }
  170. main .main_content .right .right_top .tx dl dt > .vip {
  171. position: relative;
  172. font-size: 20px;
  173. top: 2px;
  174. }
  175. main .main_content .right .right_top .tx dl dd {
  176. color: #999999;
  177. padding: 10px 0;
  178. font-size: 12px;
  179. }
  180. main .main_content .right .right_top .anniu button {
  181. display: block;
  182. border: none;
  183. outline: none;
  184. background-color: #f11717;
  185. width: 150px;
  186. height: 34px;
  187. border-radius: 20px;
  188. margin: auto;
  189. color: #fff;
  190. font-weight: bold;
  191. }
  192. main .main_content .right .right_top .anniu button:hover {
  193. cursor: pointer;
  194. width: 151px;
  195. height: 35px;
  196. }
  197. main .main_content .right .right_bottom .top {
  198. display: flex;
  199. place-content: center;
  200. }
  201. main .main_content .right .right_bottom {
  202. display: grid;
  203. grid-template-rows: 18px 1fr;
  204. margin-top: 10px;
  205. }
  206. main .main_content .right .right_bottom .bottom {
  207. margin-top: 10px;
  208. place-items: center;
  209. /* margin: 10px; */
  210. display: grid;
  211. gap: 25px;
  212. grid-template-rows: repeat(5, 18px);
  213. }
  214. main .main_content .right .right_bottom p span {
  215. font-size: 14px;
  216. margin: 0 10px;
  217. }
  218. main .main_content .right .right_bottom .top p:first-of-type a {
  219. background-color: #f11717;
  220. color: #fff;
  221. font-size: 12px;
  222. padding: 1px;
  223. }
  224. main .main_content .right .right_bottom .bottom p a {
  225. color: #b6b6b6;
  226. font-size: 14px;
  227. }
  228. main .main_content .right .right_bottom .bottom p a:hover {
  229. color: red;
  230. }
  231. /*主题内容完结*/
  232. main .main_content .main_bottom .bottom_left {
  233. background-color: #fff;
  234. border-radius: 20px;
  235. display: grid;
  236. grid-template-columns: repeat(6, 1fr);
  237. grid-auto-rows: 80px;
  238. }
  239. main .main_content .main_bottom .bottom_left a img {
  240. width: 100%;
  241. }
  242. main .main_content .main_bottom .bottom_left .left_xxlj {
  243. display: flex;
  244. flex-flow: column;
  245. place-items: center;
  246. place-content: center;
  247. }
  248. main .main_content .main_bottom .bottom_left .left_xxlj span:first-of-type {
  249. color: #333333;
  250. }
  251. main .main_content .main_bottom .bottom_left .left_xxlj span:nth-of-type(2) {
  252. color: #999999;
  253. font-size: 12px;
  254. }
  255. main .main_content .main_bottom .bottom_left a:nth-of-type(1) {
  256. display: grid;
  257. width: 130px;
  258. grid-template-columns: 40px 1fr;
  259. place-content: center;
  260. gap: 10px;
  261. }
  262. main .main_content .main_bottom .bottom_left a dt {
  263. color: #333333;
  264. font-size: 12px;
  265. }
  266. main .main_content .main_bottom .bottom_left a dd {
  267. padding: 8px 0;
  268. font-size: 12px;
  269. color: #999999;
  270. }
  271. main .main_content .main_bottom .bottom_left a dt:hover {
  272. color: red;
  273. }
  274. main .main_content .main_bottom .bottom_left a:nth-of-type(2) {
  275. display: grid;
  276. width: 130px;
  277. grid-template-columns: 40px 1fr;
  278. place-content: center;
  279. gap: 10px;
  280. }
  281. main .main_content .main_bottom .bottom_left a:nth-of-type(3) {
  282. display: grid;
  283. width: 130px;
  284. grid-template-columns: 40px 1fr;
  285. place-content: center;
  286. gap: 10px;
  287. }
  288. main .main_content .main_bottom .bottom_left a:nth-of-type(4) {
  289. display: grid;
  290. width: 130px;
  291. grid-template-columns: 40px 1fr;
  292. place-content: center;
  293. gap: 10px;
  294. }
  295. main .main_content .main_bottom .bottom_left a:nth-of-type(5) {
  296. display: grid;
  297. width: 130px;
  298. grid-template-columns: 40px 1fr;
  299. place-content: center;
  300. gap: 10px;
  301. }
  302. main .main_content .bottom_right {
  303. background-color: #fff;
  304. border-radius: 20px;
  305. display: grid;
  306. grid-template-columns: repeat(2, 1fr);
  307. }
  308. main .main_content .bottom_right a:first-of-type {
  309. display: flex;
  310. flex-flow: column;
  311. place-content: center;
  312. place-items: center;
  313. }
  314. main .main_content .bottom_right a:first-of-type + a {
  315. display: flex;
  316. flex-flow: column;
  317. place-content: center;
  318. place-items: center;
  319. }
  320. main .main_content .bottom_right a h2 {
  321. height: 16px;
  322. font-size: 12px;
  323. font-weight: bold;
  324. line-height: 16px;
  325. color: #333333;
  326. }
  327. main .main_content .bottom_right a span {
  328. color: #777;
  329. font-size: 32px;
  330. padding-bottom: 5px;
  331. }
  332. main .main_content .bottom_right a:hover h2 {
  333. color: red;
  334. }
  335. /*主体部分结束*/
Correcting teacher:PHPzPHPz

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