博客列表 >Grid实现《PHP入门精品课》模块

Grid实现《PHP入门精品课》模块

司马青衫
司马青衫原创
2020年07月01日 15:24:44658浏览

Grid实现《PHP入门精品课》模块

示例代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <link rel="stylesheet" href="iconfont/iconfont.css" />
  7. <title>Document</title>
  8. <style>
  9. * {
  10. padding: 0;
  11. margin: 0;
  12. box-sizing: border-box;
  13. }
  14. body {
  15. background-color: #f3f5f7;
  16. }
  17. a {
  18. text-decoration: none;
  19. }
  20. .container {
  21. width: 1200px;
  22. margin: 20px auto;
  23. background: #fff;
  24. border-radius: 8px;
  25. }
  26. header > h3 {
  27. width: 100%;
  28. height: 50px;
  29. font-size: 20px;
  30. line-height: 30px;
  31. padding-top: 20px;
  32. color: #555;
  33. text-align: center;
  34. }
  35. header > h3 > i {
  36. color: #1e9fff;
  37. }
  38. main {
  39. width: 100%;
  40. height: 576px;
  41. margin-top: 20px;
  42. /* grid布局 三行五列 剩余空间平均分布 */
  43. display: grid;
  44. grid-template-columns: repeat(5, 217px);
  45. grid-template-rows: repeat(3, 172px);
  46. place-content: space-evenly;
  47. }
  48. main > .item:first-of-type {
  49. /* 第一张长照片跨两行 */
  50. grid-row: span 2;
  51. }
  52. main > .item {
  53. box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
  54. position: relative;
  55. }
  56. main > .item > a > img {
  57. width: 100%;
  58. border-radius: 8px;
  59. }
  60. main > .item > a > .course-intro {
  61. width: 100%;
  62. height: 80px;
  63. border-top-left-radius: 8px;
  64. border-top-right-radius: 8px;
  65. position: absolute;
  66. transition: top 0.5s;
  67. top: 90px;
  68. padding: 0 20px;
  69. background: #fff;
  70. }
  71. main > .item > a > .course-intro:hover {
  72. top: 50px;
  73. }
  74. main > .item > a > .course-intro h3 {
  75. padding: 16px 0 6px;
  76. font-size: 14px;
  77. max-height: 40px;
  78. color: #07111b;
  79. line-height: 21px;
  80. font-weight: 400;
  81. }
  82. main > .item > a > .course-intro h3 > i {
  83. font-size: 12px;
  84. font-style: normal;
  85. line-height: 12px;
  86. border-radius: 1px;
  87. color: #fff;
  88. background-color: #93999f;
  89. margin-top: 2px;
  90. margin-right: 4px;
  91. padding: 2px;
  92. }
  93. main > .item > a > .course-bottom {
  94. width: 100%;
  95. height: 42px;
  96. padding: 0 20px;
  97. background-color: #fff;
  98. color: #93999f;
  99. font-size: 12px;
  100. line-height: 36px;
  101. position: absolute;
  102. bottom: 0px;
  103. }
  104. </style>
  105. </head>
  106. <body>
  107. <div class="container">
  108. <header>
  109. <h3>
  110. <i class="iconfont">&#xe60e;</i>
  111. PHP入门精品课
  112. <i class="iconfont">&#xe60e;</i>
  113. </h3>
  114. </header>
  115. <main>
  116. <div class="item">
  117. <a href=""><img src="images/index_learn_first.jpg" alt="" /></a>
  118. </div>
  119. <div class="item">
  120. <a href="">
  121. <img src="images/5b63c72c61569244.png" alt="" />
  122. <div class="course-intro">
  123. <h3><i>初级</i>编程学习方法分享直播公益课</h3>
  124. <p></p>
  125. </div>
  126. <div class="course-bottom"><p>1W+次播放</p></div>
  127. </a>
  128. </div>
  129. <div class="item">
  130. <a href="">
  131. <img src="images/5aa23f0ded921649.jpg" alt="" />
  132. <div class="course-intro">
  133. <h3><i>初级</i>2018前端入门_HTML5</h3>
  134. <p></p>
  135. </div>
  136. <div class="course-bottom"><p>18W+次播放</p></div>
  137. </a>
  138. </div>
  139. <div class="item">
  140. <a href="">
  141. <img src="images/5ab346fc62ce4221.jpg" alt="" />
  142. <div class="course-intro">
  143. <h3><i>初级</i>CSS视频教程-玉女心经版</h3>
  144. <p></p>
  145. </div>
  146. <div class="course-bottom"><p>10W+次播放</p></div>
  147. </a>
  148. </div>
  149. <div class="item">
  150. <a href="">
  151. <img src="images/5acc118f11d6b969.jpg" alt="" />
  152. <div class="course-intro">
  153. <h3><i>初级</i>JavaScript极速入门_玉女心经系列</h3>
  154. <p></p>
  155. </div>
  156. <div class="course-bottom"><p>18W+次播放</p></div>
  157. </a>
  158. </div>
  159. <div class="item">
  160. <a href="">
  161. <img src="images/5d1c6e0d2b744633.jpg" alt="" />
  162. <div class="course-intro">
  163. <h3><i>中级</i>独孤九贱(6)_jQuery视频教程</h3>
  164. <p></p>
  165. </div>
  166. <div class="course-bottom"><p>12W+次播放</p></div>
  167. </a>
  168. </div>
  169. <div class="item">
  170. <a href="">
  171. <img src="images/5a9fb97057b15707.jpeg" alt="" />
  172. <div class="course-intro">
  173. <h3><i>初级</i>30分钟学会网站布局</h3>
  174. <p></p>
  175. </div>
  176. <div class="course-bottom"><p>6W+次播放</p></div>
  177. </a>
  178. </div>
  179. <div class="item">
  180. <a href="">
  181. <img src="images/5d24019911a24370.jpg" alt="" />
  182. <div class="course-intro">
  183. <h3><i>初级</i>[公益直播]Web前端开发极速入门</h3>
  184. <p></p>
  185. </div>
  186. <div class="course-bottom"><p>5W+次播放</p></div>
  187. </a>
  188. </div>
  189. <div class="item">
  190. <a href="">
  191. <img src="images/5a699f1b2da2b398.jpg" alt="" />
  192. <div class="course-intro">
  193. <h3><i>初级</i>phpStudy极速入门视频教程</h3>
  194. <p></p>
  195. </div>
  196. <div class="course-bottom"><p>40W+次播放</p></div>
  197. </a>
  198. </div>
  199. <div class="item">
  200. <a href="">
  201. <img src="images/5cecd27a4348b582.jpg" alt="" />
  202. <div class="course-intro">
  203. <h3><i>中级</i>ThinkPHP6.0极速入门(视频教程)</h3>
  204. <p></p>
  205. </div>
  206. <div class="course-bottom"><p>4W+次播放</p></div>
  207. </a>
  208. </div>
  209. <div class="item">
  210. <a href="">
  211. <img src="images/5d1c6dfc9eb09885.jpg" alt="" />
  212. <div class="course-intro">
  213. <h3><i>中级</i>独孤九贱(4)_PHP视频教程</h3>
  214. <p></p>
  215. </div>
  216. <div class="course-bottom"><p>50W+次播放</p></div>
  217. </a>
  218. </div>
  219. <div class="item">
  220. <a href="">
  221. <img src="images/5a13c87351613730.jpg" alt="" />
  222. <div class="course-intro">
  223. <h3><i>初级</i>php完全自学手册</h3>
  224. <p></p>
  225. </div>
  226. <div class="course-bottom"><p>20W+次播放</p></div>
  227. </a>
  228. </div>
  229. <div class="item">
  230. <a href="">
  231. <img src="images/5b19ef2990649817.jpg" alt="" />
  232. <div class="course-intro">
  233. <h3><i>初级</i>MySQL权威开发指南(教程)</h3>
  234. <p></p>
  235. </div>
  236. <div class="course-bottom"><p>2W+次播放</p></div>
  237. </a>
  238. </div>
  239. <div class="item">
  240. <a href="">
  241. <img src="images/5d240300be85b731.jpg" alt="" />
  242. <div class="course-intro">
  243. <h3><i>中级</i>[公益直播]PHP实战开发极速入门</h3>
  244. <p></p>
  245. </div>
  246. <div class="course-bottom"><p>3W+次播放</p></div>
  247. </a>
  248. </div>
  249. </main>
  250. </div>
  251. </body>
  252. </html>

显示效果

总结

  • 基本上实现了php中文网的《PHP入门精品课》模块布局与功能
  • 使用grid布局能快速使项目定位在相应位置,只需要调整项目样式
  • 本次使用的grid布局关键代码有:
      1. main {
      2. width: 100%;
      3. height: 576px;
      4. margin-top: 20px;
      5. /* grid布局 三行五列 剩余空间平均分布 */
      6. display: grid;
      7. grid-template-columns: repeat(5, 217px);
      8. grid-template-rows: repeat(3, 172px);
      9. place-content: space-evenly;
      10. }
      11. main > .item:first-of-type {
      12. /* 第一张长照片跨两行 */
      13. grid-row: span 2;
      14. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议