博客列表 >仿PHP中文网首页部分布局

仿PHP中文网首页部分布局

弦知音的博客
弦知音的博客原创
2022年04月13日 20:42:11389浏览

仿PHP中文网首页部分布局

1. demo.html

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>仿PHP中文网首页布局</title>
  8. <link rel="stylesheet" href="static/css/my-reset.css">
  9. <link rel="stylesheet" href="static/css/my-header.css">
  10. <link rel="stylesheet" href="static/css/my-main-nav.css">
  11. </head>
  12. <body>
  13. <!-- 头部 -->
  14. <header>
  15. <!-- 顶部横条 -->
  16. <div class="top">
  17. <div class="content">
  18. <div class="tltle">PHP中文网-程序员梦开始的地方!</div>
  19. <div class="login">注册/登录</div>
  20. </div>
  21. </div>
  22. <!-- 导航 -->
  23. <div class="navs">
  24. <div class="content">
  25. <div class="logo">
  26. <a href="https://www.php.cn/" title="php中文网">
  27. <img src="static/images/logo.png" alt="php中文网">
  28. </a>
  29. </div>
  30. <div class="nav">
  31. <a href="">首页</a>
  32. <a href="">视频教程</a>
  33. <a href="">学习路径</a>
  34. <a href="">大前端培训</a>
  35. <a href="">资源下载</a>
  36. <a href="">技术文章</a>
  37. <a href="">社区</a>
  38. <a href="">APP下载</a>
  39. </div>
  40. <div class="search">
  41. <input type="search" name="search" placeholder="请输入关键词搜索">
  42. <span class="iconfont icon-Magnifier"></span>
  43. </div>
  44. </div>
  45. </div>
  46. </header>
  47. <!-- 主体 -->
  48. <main>
  49. <!-- 第一块 -->
  50. <div class="firBox">
  51. <!-- 2行3列 -->
  52. <!-- 侧边栏目 -->
  53. <div class="menu">
  54. <a href="">php开发</a>
  55. <a href="">大前端</a>
  56. <a href="">后端开发</a>
  57. <a href="">数据库</a>
  58. <a href="">移动端</a>
  59. <a href="">运维开发</a>
  60. <a href="">UI设计</a>
  61. <a href="">计算机基础</a>
  62. </div>
  63. <!-- banner轮播图 -->
  64. <div class="banner">
  65. <a href=""><img src="static/images/slider.jpeg" alt="轮播图1"></a>
  66. </div>
  67. <!-- sider -->
  68. <div class="sider">
  69. <div class="userInfo">
  70. <div class="userCont1">
  71. <a href=""><img src="static/images/user-pic.jpeg" alt="小头像"></a>
  72. <dl>
  73. <dt><a href=''>一步莲华</a></dt>
  74. <dd>P豆:37.5</dd></dd>
  75. </dl>
  76. </div>
  77. <div class="userCont2">
  78. <span><a href="">我的学习</a></span>
  79. </div>
  80. </div>
  81. <div class="wenda">
  82. <div class="wenda-tit">
  83. <span>问答社区</span>
  84. <a href="">答疑</a>
  85. </div>
  86. <div class="wenda-tj">
  87. <p><span>头条</span><a href="">总结往年大前端技术趋势,展望2022...</a></p>
  88. <p><span>活动</span><a href="">限时减免>></a></p>
  89. <p><span>新班</span><a href="">大前端线上班</a></p>
  90. <p><span>招募</span><a href="">课程合作计划</a></p>
  91. <p><span>公告</span><a href="">APP上线啦</a></p>
  92. </div>
  93. </div>
  94. </div>
  95. <!-- 底部栏目 -->
  96. <div class="bottom-menu">
  97. <div class="desc">
  98. <div class="tit">学习路径</div>
  99. <span>全部7个&gt;</span>
  100. </div>
  101. <ul class="detail">
  102. <li>
  103. <img src="static/images/dgjj.png" alt="独孤九贱">
  104. <a href="">独孤九贱</a>
  105. <span>9门课程</span>
  106. </li>
  107. <li>
  108. <img src="static/images/ynxj.png" alt="独孤九贱">
  109. <a href="">玉女心经</a>
  110. <span>5门课程</span>
  111. </li>
  112. <li>
  113. <img src="static/images/tlbb.png" alt="独孤九贱">
  114. <a href="">天龙八部</a>
  115. <span>3门课程</span>
  116. </li>
  117. <li>
  118. <img src="static/images/phpkjkf.png" alt="独孤九贱">
  119. <a href="">自学指南</a>
  120. <span>19门课程</span>
  121. </li>
  122. <li>
  123. <img src="static/images/phpksrm.png" alt="独孤九贱">
  124. <a href="">趣味闯关</a>
  125. <span>22门课程</span>
  126. </li>
  127. <!-- <li>
  128. <img src="static/images/dgjj.png" alt="独孤九贱">
  129. <a href="">入门教程</a></a>
  130. <span>22门课程</span>
  131. </li>
  132. <li>
  133. <img src="static/images/dgjj.png" alt="独孤九贱">
  134. <a href="">PHP直播班</a>
  135. <span>三个阶段</span>
  136. </li> -->
  137. </ul>
  138. </div>
  139. <!-- 底部关注 -->
  140. <div class="attention">
  141. <ul class="att">
  142. <li><a href="">
  143. <span class="iconfont icon-weixin-copy"></span>
  144. <span>官方公众号</span>
  145. </a>
  146. </li>
  147. <li><a href="">
  148. <span class="iconfont icon-qq"></span>
  149. <span>官方QQ群</span>
  150. </a>
  151. </li>
  152. </ul>
  153. </div>
  154. </div>
  155. <!-- 第二块 -->
  156. <div class="secBox">
  157. <div class="secTit">
  158. <h2>最新课程</h2>
  159. <a href="">更多&gt;</a>
  160. </div>
  161. <!-- 课程列表 -->
  162. <ul class="courses">
  163. <li>
  164. <span><a href="">H5+CSS3从入门到精通</a></span>
  165. <dl>
  166. <dt><i>初级</i><a href="">前端基础HTML5+CSS3从入门到精通</a></dt>
  167. <dd><p>8053次学习</p><em class="iconfont icon-xinghao"><a href="">收藏</a></em></dd>
  168. </dl>
  169. </li>
  170. <li>
  171. <span><a href="">JavaScript基础语法讲解</a></span>
  172. <dl>
  173. <dt><i>初级</i><a href="">JavaScript基础语法讲解</a></dt>
  174. <dd><p>8053次学习</p><em>收藏</em></dd>
  175. </dl>
  176. </li>
  177. <li>
  178. <span><a href="">HTTP基础原理及应用</a></span>
  179. <dl>
  180. <dt><i>初级</i><a href="">HTTP基础原理及应用</a></dt>
  181. <dd><p>8053次学习</p><em class="iconfont icon-xinghao"><a href="">收藏</a></em></dd>
  182. </dl>
  183. </li>
  184. <li>
  185. <span><a href="">HTTP协议基础知识掌握</a></span>
  186. <dl>
  187. <dt><i>初级</i><a href="">HTTP协议基础知识掌握</a></dt>
  188. <dd><p>8053次学习</p><em>收藏</em></dd>
  189. </dl>
  190. </li>
  191. <li>
  192. <span><a href="">API接口开发规范</a></span>
  193. <dl>
  194. <dt><i>初级</i><a href="">API接口开发规范</a></dt>
  195. <dd><p>8053次学习</p><em>收藏</em></dd>
  196. </dl>
  197. </li>
  198. <li>
  199. <span><a href="">MySQL查询优化方案</a></span>
  200. <dl>
  201. <dt><i>初级</i><a href="">MySQL查询优化方案</a></dt>
  202. <dd><p>8053次学习</p><em>收藏</em></dd>
  203. </dl>
  204. </li>
  205. <li>
  206. <span><a href="">Promise教程从入门到精通</a></span>
  207. <dl>
  208. <dt><i>初级</i><a href="">Promise教程从入门到精通</a></dt>
  209. <dd><p>8053次学习</p><em>收藏</em></dd>
  210. </dl>
  211. </li>
  212. <li>
  213. <span><a href="">Bootstrap框架入门讲解</a></span>
  214. <dl>
  215. <dt><i>初级</i><a href="">Bootstrap框架入门讲解</a></dt>
  216. <dd><p>8053次学习</p><em>收藏</em></dd>
  217. </dl>
  218. </li>
  219. <li>
  220. <span><a href="">Linux一周时间轻松掌握</a></span>
  221. <dl>
  222. <dt><i>初级</i><a href="">Linux一周时间轻松掌握</a></dt>
  223. <dd><p>8053次学习</p><em>收藏</em></dd>
  224. </dl>
  225. </li>
  226. <li>
  227. <span><a href="">仿美团APP项目JS实战</a></span>
  228. <dl>
  229. <dt><i>初级</i><a href="">仿美团APP项目JS实战</a></dt>
  230. <dd><p>8053次学习</p><em>收藏</em></dd>
  231. </dl>
  232. </li>
  233. </ul>
  234. </div>
  235. </main>
  236. <!-- 底部 -->
  237. <footer></footer>
  238. </body>
  239. </html>

2. static/css/my-reset.css

  1. /* 引入阿里图标库 */
  2. @import url(//at.alicdn.com/t/font_3325033_28ckjqi2ecx.css);
  3. *{
  4. margin: 0;
  5. padding: 0;
  6. box-sizing: border-box;
  7. }
  8. a{
  9. text-decoration: none;
  10. color: #333;
  11. }
  12. li{
  13. list-style: none;
  14. }
  15. body{
  16. background-color: #F3F5F7;
  17. }
  18. input,textarea{
  19. border: none;
  20. outline: none;
  21. }

3. static/css/my-header.css

  1. /* top */
  2. header .top{
  3. width: 100vw;
  4. height: 40px;
  5. background-color: rgb(52,52,52);
  6. color: rgb(196, 191, 191);
  7. }
  8. header .top .content{
  9. width: 1200px;
  10. /* 定义网格布局 */
  11. display: grid;
  12. /* 2列 230px 75px */
  13. grid-template-columns: 230px 75px;
  14. /* 网格行高 */
  15. grid-auto-rows: 40px;
  16. /* 子元素分散对齐 */
  17. place-content: space-between;
  18. /* 子元素 垂直居中 靠左 */
  19. place-items: center start;
  20. /* 两端对齐 */
  21. margin: auto;
  22. font-size: 14px;
  23. }
  24. /* navs */
  25. header .navs{
  26. width: 100vw;
  27. height: 90px;
  28. background-color: #fff;
  29. }
  30. header .navs .content{
  31. width: 1200px;
  32. /* 定义网格布局 */
  33. display: grid;
  34. /* 2列 230px 75px */
  35. grid-template-columns: 140px 1fr 200px;
  36. /* 网格行高 */
  37. grid-auto-rows: 90px;
  38. /* 网格行列间距 */
  39. gap: 10px;
  40. /* 子元素分散对齐 */
  41. place-content: space-between;
  42. /* 子元素 垂直居中 靠左 */
  43. place-items: center start;
  44. /* 两端对齐 */
  45. margin: auto;
  46. }
  47. header .navs .content .logo img{
  48. width: 100%;
  49. }
  50. header .navs .content .nav a{
  51. padding: 0 10px;
  52. }
  53. header .navs .content .nav a:hover,header .navs .content .nav a:first-of-type,header .navs .content .nav a:last-of-type{
  54. color: red;
  55. font-weight: bold;
  56. }
  57. /* search */
  58. header .navs .content .search{
  59. display: flex;
  60. }
  61. header .navs .content .search input[type='search']{
  62. border-radius: 20px;
  63. background-color: rgb(247,248,250);
  64. width: 200px;
  65. height: 40px;
  66. padding-left: 20px;
  67. }
  68. header .navs .content .search .icon-Magnifier{
  69. position: relative;
  70. font-size: 24px;
  71. left: -40px;
  72. top: 8px;
  73. color: #ccc;
  74. }

4. static/css/my-main-nav.css

  1. main{
  2. display: grid;
  3. place-content: center;
  4. font-size: 14px;
  5. }
  6. main .firBox{
  7. /* 2行3列 */
  8. display: grid;
  9. grid-template-columns:160px 1fr 190px;
  10. grid-template-rows: 400px 80px;
  11. gap: 20px;
  12. place-content: center;
  13. margin: 30px 0px;
  14. }
  15. main .firBox>*{
  16. background-color: #fff;
  17. border-radius: 20px;
  18. }
  19. /* menu 左侧菜单 */
  20. main .firBox .menu{
  21. display: grid;
  22. place-items: center;
  23. padding: 20px 0;
  24. }
  25. main .firBox .menu a{
  26. border-radius: 20px;
  27. padding: 10px 20px;
  28. min-width: 120px;
  29. text-align: center;
  30. }
  31. main .firBox .menu a:hover{
  32. color: red;
  33. background-color: rgb(255, 0, 0,.1);
  34. }
  35. /* 轮播图 */
  36. main .firBox .banner img{
  37. border-radius: 10px;
  38. width: 100%;
  39. }
  40. /* 右侧 */
  41. main .firBox .sider{
  42. display: grid;
  43. grid-template-columns: 1fr;
  44. grid-template-rows: 140px 1fr;
  45. place-content: center;
  46. }
  47. main .firBox .sider .userInfo{
  48. display: grid;
  49. grid-template-rows: 60px 80px;
  50. place-items: center;
  51. padding: 15px 0 10px;
  52. border-bottom: 1px solid rgb(209, 209, 209);
  53. }
  54. main .firBox .sider .userCont1{
  55. width: 155px;
  56. display: grid;
  57. grid-template-columns: 40px 1fr;
  58. gap: 15px;
  59. }
  60. main .firBox .sider .userCont1 a>img{
  61. width: 40px;
  62. border-radius: 20px;
  63. }
  64. main .firBox .sider .userCont1 dl dt{
  65. margin-top: -5px;
  66. }
  67. main .firBox .sider .userCont1 dl dt>a{
  68. font-size: 14px;
  69. font-weight:bold;
  70. }
  71. main .firBox .sider .userCont1 dl dd{
  72. font-size: 12px;
  73. color: #999;
  74. margin-top: 5px;
  75. }
  76. main .firBox .sider .userCont2{
  77. position: relative;
  78. bottom: 20px;
  79. }
  80. main .firBox .sider .userCont2 span{
  81. background-color: red;
  82. width: 80%;
  83. }
  84. main .firBox .sider .userCont2 span a{
  85. color: #fff;
  86. font-size: 14px;
  87. display: block;
  88. background-color: red;
  89. width: 150px;
  90. text-align: center;
  91. border-radius: 20px;
  92. height: 34px;
  93. line-height: 34px;
  94. }
  95. main .firBox .sider .userCont2 span a:hover{
  96. background-color: rgb(196, 6, 6);
  97. }
  98. /* 问答 2行1列*/
  99. main .firBox .sider .wenda{
  100. display: grid;
  101. grid-template-rows: 40px 1fr;
  102. padding: 10px 20px;
  103. }
  104. main .firBox .sider .wenda .wenda-tit{
  105. margin-top: 10px;
  106. }
  107. main .firBox .sider .wenda .wenda-tit span{
  108. line-height: 18px;
  109. margin-right: 10px;
  110. color: #515151;
  111. }
  112. main .firBox .sider .wenda .wenda-tit a{
  113. color: white;
  114. background-color: red;
  115. font-size: 10px;
  116. padding: 1px 3px;
  117. }
  118. main .firBox .sider .wenda .wenda-tj p{
  119. margin-top: 17px;
  120. }
  121. main .firBox .sider .wenda .wenda-tj p:first-of-type{
  122. margin-top: 0;
  123. }
  124. main .firBox .sider .wenda .wenda-tj p>span{
  125. line-height: 18px;
  126. margin-right: 10px;
  127. color: #515151;
  128. }
  129. main .firBox .sider .wenda .wenda-tj p>a{
  130. color: rgb(182,182,182);
  131. }
  132. /* 底部左侧占2列 */
  133. main .firBox .bottom-menu{
  134. grid-column: span 2;
  135. }
  136. /* 底部左侧 */
  137. main .firBox .bottom-menu{
  138. display: grid;
  139. grid-template-columns: 100px 1fr;
  140. }
  141. main .firBox .bottom-menu .desc{
  142. display: grid;
  143. place-items: center;
  144. padding: 16px;
  145. }
  146. main .firBox .bottom-menu .desc span{
  147. color: rgb(153,153,153);
  148. font-size: 12px;
  149. }
  150. main .firBox .bottom-menu .detail{
  151. display: flex;
  152. place-content: space-between;
  153. place-items: center;
  154. }
  155. main .firBox .bottom-menu .detail img{
  156. width: 100%;
  157. grid-row: span 2;
  158. }
  159. main .firBox .bottom-menu .detail li{
  160. display: grid;
  161. grid-template-columns: 36px 85px;
  162. gap: 0 10px;
  163. }
  164. main .firBox .bottom-menu .detail li span{
  165. color: rgb(153,153,153);
  166. font-size: 12px;
  167. }
  168. /* 底部右侧 */
  169. main .firBox .attention .att{
  170. display: flex;
  171. place-content: space-between;
  172. place-items: center;
  173. gap:0 20px;
  174. width: 150px;
  175. margin: 15px auto;
  176. }
  177. main .firBox .attention .att li a .iconfont{
  178. font-size: 30px;
  179. color: rgb(153,153,153);
  180. }
  181. main .firBox .attention .att li a{
  182. display: grid;
  183. grid-template-rows: 30px 25px;
  184. place-items: center;
  185. }
  186. main .firBox .attention .att li a span{
  187. font-weight: bold;
  188. font-size: 12px;
  189. }
  190. /* 第二块 secBox */
  191. main .secBox{
  192. margin-top: 10px;
  193. }
  194. main .secBox .secTit{
  195. display: grid;
  196. grid-template-columns: 90px 80px;
  197. place-content: space-between;
  198. place-items: center;
  199. }
  200. main .secBox .secTit h2{
  201. font-size: 22px;
  202. font-weight: bold;
  203. color: #333;
  204. line-height: 40px;
  205. }
  206. main .secBox .secTit a{
  207. font: 18px;
  208. color: #999;
  209. background-color: #f0f1f4;
  210. width: 100%;
  211. text-align: center;
  212. border-radius: 20px;
  213. line-height: 30px;
  214. }
  215. main .secBox .courses{
  216. display: grid;
  217. grid-template-columns: repeat(5,224px);
  218. grid-template-rows: repeat(2,235px);
  219. place-content: space-between;
  220. place-items: center;
  221. row-gap: 20px;
  222. margin-top: 10px;
  223. }
  224. main .secBox .courses li{
  225. display: grid;
  226. grid-template-rows: 130px 1fr;
  227. background-color: #fff;
  228. border-radius: 10px;
  229. }
  230. main .secBox .courses li span{
  231. border-radius: 10px 10px 0 0;
  232. }
  233. main .secBox .courses li:first-of-type span{
  234. background: linear-gradient(to bottom right, RGB(72,118,230),RGB(153,101,235));
  235. }
  236. main .secBox .courses li:nth-of-type(2) span{
  237. background: linear-gradient(to bottom right, RGB(27,132,236),RGB(39,229,241));
  238. }
  239. main .secBox .courses li:nth-of-type(3) span{
  240. background: linear-gradient(to bottom right, RGB(237,73,106),RGB(255,182,96));
  241. }
  242. main .secBox .courses li:nth-of-type(4) span{
  243. background: linear-gradient(to bottom right, RGB(93,60,255),RGB(219,99,255));
  244. }
  245. main .secBox .courses li:nth-of-type(5) span{
  246. background: linear-gradient(to bottom right, RGB(70,129,252),RGB(81,43,240));
  247. }
  248. main .secBox .courses li:nth-of-type(6) span{
  249. background: linear-gradient(to bottom right, RGB(249,86,117),RGB(219,34,30));
  250. }
  251. main .secBox .courses li:nth-of-type(7) span{
  252. background: linear-gradient(to bottom right, RGB(255,112,155),RGB(254,70,105));
  253. }
  254. main .secBox .courses li:nth-of-type(8) span{
  255. background: linear-gradient(to bottom right, RGB(252,115,250),RGB(244,195,243));
  256. }
  257. main .secBox .courses li:nth-of-type(9) span{
  258. background: linear-gradient(to bottom right, RGB(247,151,30),RGB(255,210,0));
  259. }
  260. main .secBox .courses li:last-of-type span{
  261. background: linear-gradient(to bottom right, RGB(69,186,91),RGB(137,199,104));
  262. }
  263. main .secBox .courses li span a{
  264. color: #fff;
  265. font-weight: bold;
  266. font-size: 20px;
  267. text-align: center;
  268. padding: 35px 30px;
  269. display: table-cell;
  270. vertical-align: middle;
  271. }
  272. main .secBox .courses li dl{
  273. width: 188px;
  274. margin: auto;
  275. height: 105px;
  276. }
  277. main .secBox .courses li dl dt{
  278. margin-top: 18px;
  279. line-height: 25px;
  280. }
  281. main .secBox .courses li dl dt i{
  282. background-color: #E0E8FC;
  283. color: #298AFD;
  284. font-size: 11px;
  285. font-style: normal;
  286. padding: 2px 4px;
  287. border-radius: 2px;
  288. margin-right: 10px;
  289. }
  290. main .secBox .courses li dl dd{
  291. color: #b7b7b7;
  292. font-size: 12px;
  293. line-height: 30px;
  294. display: flex;
  295. place-content: space-between;
  296. }
  297. main .secBox .courses li dl dd em{
  298. font-style: normal;
  299. font-size: 12px;
  300. }
  301. main .secBox .courses li dl dd em a{
  302. color: #b7b7b7;
  303. padding-left:5px;
  304. }

5. 效果图


连续看了2天的教程,今天把这个作业全部做了一遍,到现在快晚上9点了才完成。虽然时间花得久,但是感触良多。感觉布局万物皆可grid,而且grid还能精简很多代码。

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