Blogger Information
Blog 36
fans 1
comment 0
visits 26405
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用grid 和 flex仿php中文网首页布局
早晨
Original
382 people have browsed it

运行效果:

代码:

  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>使用grid 和 flex仿PHP中文网首页布局</title>
  8. <link rel="stylesheet" href="static/css/index.css">
  9. </head>
  10. <body>
  11. <!-- 页眉 -->
  12. <header>
  13. <!-- 顶部 -->
  14. <div class="top">
  15. <div class="con">
  16. <!-- 左边:顶部标题 -->
  17. <div class="con_l">PHP中文网 程序员梦开始的地方!</div>
  18. <!-- 右边:用户信息 -->
  19. <div class="con_r">
  20. <a href="" class="iconfont icon-xiaoxi"></a>
  21. <a href=""><img src="static/images/user_avatar.jpg" alt=""></a>
  22. </div>
  23. </div>
  24. </div>
  25. <!-- 导航 -->
  26. <div class="navs">
  27. <div class="navs-con">
  28. <a href=""><img src="static/images/logo.png" alt=""></a>
  29. <nav>
  30. <a href="">网站首页</a>
  31. <a href="">视频教程</a>
  32. <a href="">学习路径</a>
  33. <a href="">PHP培训</a>
  34. <a href="">资源下载</a>
  35. <a href="">技术文章</a>
  36. <a href="">社区</a>
  37. </nav>
  38. <div class="search">
  39. <input type="search" placeholder="输入关键字">
  40. <span class="iconfont icon-sousuo"></span>
  41. </div>
  42. </div>
  43. </div>
  44. </header>
  45. <!-- 主体内容 -->
  46. <main>
  47. <div class="m-navs">
  48. <div class="m-navs-l">
  49. <a href="">php开发</a>
  50. <a href="">大前端</a>
  51. <a href="">后端开发</a>
  52. <a href="">数据库</a>
  53. <a href="">移动端</a>
  54. <a href="">运维开发</a>
  55. <a href="">UI设计</a>
  56. <a href="">计算机基础</a>
  57. </div>
  58. <div class="slider">
  59. <a href=""><img src="static/images/1.png" alt="" /></a>
  60. </div>
  61. <div class="m-navs-r">
  62. <!-- 用户 -->
  63. <div class="user">
  64. <div class="user_l">
  65. <img src="static/images/user_avatar.jpg" alt="">
  66. <a href="">用户名称</a>
  67. <span>P豆 2000</span>
  68. </div>
  69. </div>
  70. <div class="user_r"><button class="btn">我的学习</button></div>
  71. <!-- 列表 -->
  72. <div class="list">
  73. <p class="cont1">问答社区</p>
  74. <p class="cont2"><span>头条</span><a href="">20期PHP线上班</a></p>
  75. <p class="cont2"><span>福利</span><a href="">20期PHP线上班</a></p>
  76. <p class="cont2"><span>新班</span><a href="">20期PHP线上班</a></p>
  77. <p class="cont2"><span>招募</span><a href="">课程合作计划</a></p>
  78. <p class="cont2"><span>公告</span><a href="">APP上线哟</a></p>
  79. </div>
  80. </div>
  81. <div class="m-navs-b-l">
  82. <div class="desc">
  83. <div class="title">学习路径</div>
  84. <span>全部7个</span>
  85. </div>
  86. <ul class="detail">
  87. <li onclick="">
  88. <img src="static/images/dgjj.png" alt="" />
  89. <a href="">独孤九贱</a>
  90. <span>9门课程</span>
  91. </li>
  92. <li onclick="">
  93. <img src="static/images/ynxj.png" alt="" />
  94. <a href="">独孤九贱</a>
  95. <span>9门课程</span>
  96. </li>
  97. <li onclick="">
  98. <img src="static/images/tlbb.png" alt="" />
  99. <a href="">独孤九贱</a>
  100. <span>9门课程</span>
  101. </li>
  102. <li onclick="">
  103. <img src="static/images/phpkjkf.png" alt="" />
  104. <a href="">独孤九贱</a>
  105. <span>9门课程</span>
  106. </li>
  107. <li onclick="">
  108. <img src="static/images/phpksrm.png" alt="" />
  109. <a href="">独孤九贱</a>
  110. <span>9门课程</span>
  111. </li>
  112. </ul>
  113. </div>
  114. <div class="m-navs-b-r">
  115. <ul class="wx-qq">
  116. <a href="" class="iconfont icon-weixin3f"><li>官方公众号</li></a>
  117. <a href="" class="iconfont icon-QQ-circle-fill"><li>官方QQ群</li></a>
  118. </ul>
  119. </div>
  120. </div>
  121. </main>
  122. </body>
  123. </html>

CSS样式

  1. @import url(font/iconfont.css);
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. a{
  8. text-decoration: none;
  9. color: #555;
  10. }
  11. body{
  12. background-color: #f3f5f7;
  13. }
  14. li{
  15. list-style: none;
  16. }
  17. .top {
  18. width: 100vw;
  19. height: 40px;
  20. background-color: #343434;
  21. color: aliceblue;
  22. }
  23. .top .con {
  24. width: 1200px;
  25. display: grid;
  26. grid-template-columns: 400px 100px;
  27. grid-auto-rows: 40px;
  28. place-content: space-between;
  29. place-items: center start;
  30. margin: auto;
  31. }
  32. .top .con .con_l{
  33. font-size: larger;
  34. font-weight: lighter;
  35. }
  36. .top .con img{
  37. width: 30%;
  38. border-radius: 50%;
  39. }
  40. .top .con .con_r{
  41. place-items: center;
  42. }
  43. .top .con .con_r .iconfont{
  44. color: #eee;
  45. font-size: larger;
  46. }
  47. .navs{
  48. width: 100vw;
  49. height: 90px;
  50. background-color: #fff;
  51. box-shadow: 0 5px 15px rgd(0,0,0,0.1);
  52. }
  53. .navs .navs-con {
  54. width: 1200px;
  55. display: grid;
  56. grid-template-columns: 140px 1fr 200px;
  57. grid-auto-rows: 90px;
  58. margin: auto;
  59. gap: 10px;
  60. place-items: center start;
  61. }
  62. .navs .navs-con nav{
  63. display: flex;
  64. }
  65. .navs .navs-con nav a {
  66. padding: 0 10px;
  67. }
  68. .navs .navs-con nav a:hover,
  69. .navs .navs-con nav a:active {
  70. font-weight: bold;
  71. color: red;
  72. }
  73. .navs .navs-con img {
  74. width: 100%;
  75. }
  76. .navs .navs-con .search {
  77. display: flex;
  78. }
  79. .navs .navs-con .search input[type='search']{
  80. width: 200px;
  81. height: 36px;
  82. border: none;
  83. background-color: #eee;
  84. outline: none;
  85. border-radius: 10px;
  86. padding-left: 10px;
  87. }
  88. .navs .navs-con .search .icon-sousuo{
  89. font-size: 22px;
  90. color: #ccc;
  91. position: relative;
  92. left: -30px;
  93. top:8px;
  94. }
  95. .navs .navs-con .search .icon-sousuo:hover{
  96. color: red;
  97. cursor: pointer;
  98. }
  99. main{
  100. font-size: 14px;
  101. }
  102. .m-navs{
  103. display: grid;
  104. grid-template-rows: 400px 80px;
  105. grid-template-columns: 160px 810px 190px;
  106. gap: 20px;
  107. place-content: center;
  108. margin: 30px 0;
  109. }
  110. .m-navs > * {
  111. background-color: #fff;
  112. border-radius: 20px;
  113. }
  114. .m-navs .m-navs-b-l{
  115. grid-column: span 2;
  116. }
  117. .m-navs .m-navs-l{
  118. padding: 20px 0;
  119. display: grid;
  120. place-items: center;
  121. }
  122. .m-navs .m-navs-l a{
  123. padding: 10px 20px;
  124. }
  125. .m-navs .m-navs-l a:hover{
  126. border-radius: 20px;
  127. color: red;
  128. background-color: rgb(250,230,227);
  129. }
  130. .m-navs .slider img{
  131. width: 100%;
  132. border-radius: 20px;
  133. }
  134. .m-navs .m-navs-r .user {
  135. display: flex;
  136. place-items: center;
  137. place-content: space-between;
  138. padding: 20px;
  139. }
  140. .m-navs .m-navs-r .user .user_l{
  141. display: grid;
  142. grid-template-columns: 50px 100px;
  143. gap: 0 10px;
  144. place-items: center start;
  145. }
  146. .m-navs .m-navs-r .user_r{
  147. height: 60px;
  148. padding: 20px;
  149. border-bottom:1px solid rgb(223, 223, 223);
  150. }
  151. .m-navs .m-navs-r .user_r .btn {
  152. width: 150px;
  153. height: 30px;
  154. text-align: center;
  155. background-color: red;
  156. color: white;
  157. border: none;
  158. border-radius: 20px;
  159. font-weight: 30px;
  160. }
  161. .m-navs .m-navs-r .user_r .btn:hover{
  162. background-color: rgb(194, 2, 2);
  163. }
  164. .m-navs .m-navs-r .list{
  165. padding: 0 15px;
  166. }
  167. .m-navs .m-navs-r .list p{
  168. margin-top: 17px;
  169. }
  170. .m-navs .m-navs-r .list .cont1{
  171. height: 18px;
  172. line-height: 18px;
  173. overflow: hidden;
  174. font-weight: bolder;
  175. }
  176. .m-navs .m-navs-r .list .cont2 span{
  177. font-weight: bold;
  178. padding-right: 10px;
  179. }
  180. .m-navs .m-navs-r .list .cont1 span{
  181. color: #333333;
  182. }
  183. .m-navs .m-navs-r .user .user_l img{
  184. width: 100%;
  185. grid-row: span 2;
  186. border-radius: 50%;
  187. }
  188. .m-navs .m-navs-r .user .user_l a {
  189. font-size: 16px;
  190. font-weight: bold;
  191. }
  192. .m-navs .m-navs-r .user .user_l span {
  193. font-size: 12px;
  194. text-align: center;
  195. }
  196. .m-navs .m-navs-b-l{
  197. display: grid;
  198. grid-template-columns: 100px 1fr;
  199. }
  200. .m-navs .m-navs-b-l .desc{
  201. padding: 16px 0;
  202. display: grid;
  203. place-items: center;
  204. }
  205. .m-navs .m-navs-b-l .desc span{
  206. font-size: 12px;
  207. color: #343434;
  208. }
  209. .m-navs .m-navs-b-l .detail{
  210. display: flex;
  211. place-items: center;
  212. place-content: space-between;
  213. padding: 20px;
  214. }
  215. .m-navs .m-navs-b-l .detail li {
  216. display: grid;
  217. grid-template-columns: 36px 85px;
  218. grid-template-columns: repeat(2,36);
  219. gap: 0 10px;
  220. place-items: center start;
  221. }
  222. .m-navs .m-navs-b-l .detail img{
  223. width: 100%;
  224. grid-row: span 2;
  225. }
  226. .m-navs .m-navs-b-l .detail li a {
  227. font-size: 14px;
  228. }
  229. .m-navs .m-navs-b-l .detail li a:hover{
  230. color: crimson;
  231. }
  232. .m-navs .m-navs-b-l .detail li span{
  233. font-size: 12px;
  234. color: #555;
  235. }
  236. .m-navs .m-navs-b-r .wx-qq{
  237. display: grid;
  238. grid-template-columns: 90px 90px;
  239. gap: 10px;
  240. place-items: center;
  241. }
  242. .m-navs .m-navs-b-r .wx-qq li{
  243. font-size: 14px;
  244. }
  245. .m-navs .m-navs-b-r .wx-qq .icon-weixin3f,
  246. .m-navs .m-navs-b-r .wx-qq .icon-QQ-circle-fill{
  247. font-size: 40px;
  248. text-align: center;
  249. padding: 10px;
  250. }
  251. .m-navs .m-navs-b-r .wx-qq a:hover{
  252. color: red;
  253. }
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!