博客列表 >仿php中文网课程模块grid布局

仿php中文网课程模块grid布局

肖傲的博客
肖傲的博客原创
2020年06月30日 14:32:33623浏览
  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. <title>php入门精品课程布局</title>
  7. <style>
  8. * {
  9. /* 样式初始化 */
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. a {
  15. text-decoration: none;
  16. }
  17. .course {
  18. width: 1200px;
  19. height: 660px;
  20. margin: auto;
  21. border-radius: 10px;
  22. box-shadow: 0 0 5px #888888;
  23. background-color: #fff;
  24. }
  25. .title {
  26. display: flex;
  27. height: 80px;
  28. justify-content: center;
  29. align-items: center;
  30. }
  31. .title > h3 {
  32. font-size: 20px;
  33. color: #4d555d;
  34. }
  35. .container {
  36. width: 1180px;
  37. height: 550px;
  38. margin: auto;
  39. display: grid;
  40. grid-template-columns: repeat(5, 1fr);
  41. grid-template-rows: repeat(3, 1fr);
  42. gap: 20px;
  43. }
  44. /* 设置弹性容器 垂直 不换行 */
  45. .container .item:not(:first-of-type) {
  46. display: flex;
  47. flex-flow: column nowrap;
  48. justify-content: flex-end;
  49. }
  50. .container > .item {
  51. /* border: 1px solid #000; */
  52. width: 217px;
  53. height: 172px;
  54. position: relative;
  55. box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.1);
  56. place-content: space-between;
  57. overflow: hidden;
  58. }
  59. .container > div {
  60. border-radius: 10px;
  61. }
  62. .container > .item:first-of-type {
  63. grid-row: span 2;
  64. height: 360px;
  65. box-shadow: none;
  66. /* background-color: steelblue; */
  67. }
  68. /* 让图片缩放并靠上 */
  69. .container > .item > img {
  70. width: 100%;
  71. position: absolute;
  72. top: 0;
  73. }
  74. /* 用绝对定位让span靠底部定位 */
  75. .container > .item > span:first-of-type {
  76. font-size: 12px;
  77. color: #93999f;
  78. position: absolute;
  79. bottom: 0;
  80. width: 100%;
  81. height: 42px;
  82. line-height: 42px;
  83. padding: 0 20px;
  84. background: #fff;
  85. /* border: 1px solid red; */
  86. }
  87. /* 用相对定位进行定位,并调整高度值让h3与固定的span之间重叠让多余的字隐藏 */
  88. .container > .item > h3 {
  89. font-size: 14px;
  90. font-weight: 400;
  91. position: relative;
  92. padding: 10px 10px 0 10px;
  93. min-height: 84px;
  94. top: 10px;
  95. /* overflow: hidden; */
  96. border-radius: 5%;
  97. background-color: #fff;
  98. /* 减慢浮出效果 */
  99. transition: 0.6s;
  100. /* border: 1px solid red; */
  101. }
  102. .container > .item > h3 > i {
  103. color: white;
  104. background-color: #93999f;
  105. font-style: normal;
  106. font-size: 14px;
  107. }
  108. .container > .item > h3 > p {
  109. font-size: 12px;
  110. color: #93999f;
  111. text-align: center;
  112. height: 40px;
  113. line-height: 20px;
  114. padding-top: 10px;
  115. }
  116. .container > .item > h3:hover {
  117. background-color: #fff;
  118. min-height: 130px;
  119. }
  120. </style>
  121. </head>
  122. <body>
  123. <div class="course">
  124. <div class="title">
  125. <span></span>
  126. <h3>PHP入门精品课程</h3>
  127. <span></span>
  128. </div>
  129. <div class="container">
  130. <div class="item">
  131. <img src="images/1.jpg" alt="" />
  132. </div>
  133. <div class="item">
  134. <img src="images/2.png" alt="" />
  135. <h3>
  136. <i>初级</i>
  137. 编程学习方法分享直播公益课
  138. </h3>
  139. <span>1W+次播放</span>
  140. </div>
  141. <div class="item">
  142. <img src="images/3.jpg" alt="" />
  143. <h3>
  144. <i>初级</i>
  145. 2018前端入门_HTML5
  146. </h3>
  147. <span>18W+次播放</span>
  148. </div>
  149. <div class="item">
  150. <img src="images/4.jpg" alt="" />
  151. <h3>
  152. <i>初级</i>
  153. CSS视频教程-玉女心经版
  154. <p>本章节讲解的是有关CSS基础的内容,轻松明快,适合新手观看学习。</p>
  155. </h3>
  156. <span>10W+次播放</span>
  157. </div>
  158. <div class="item">
  159. <img src="images/5.jpg" alt="" />
  160. <h3>
  161. <i>初级</i>
  162. JavaScript极速入门_玉女心经系列
  163. </h3>
  164. <span>18W+次播放</span>
  165. </div>
  166. <div class="item">
  167. <img src="images/6.jpg" alt="" />
  168. <h3>
  169. <i>初级</i>
  170. 独孤九贱(6)_jQuery视频教程
  171. </h3>
  172. <span>12W+次播放</span>
  173. </div>
  174. <div class="item">
  175. <img src="images/7.jpeg" alt="" />
  176. <h3>
  177. <i>初级</i>
  178. 30分钟学会网站布局
  179. </h3>
  180. <span>6W+次播放</span>
  181. </div>
  182. <div class="item">
  183. <img src="images/8.jpg" alt="" />
  184. <h3>
  185. <i>初级</i>
  186. [公益直播]Web前端开发极速入门]
  187. </h3>
  188. <span>5W+次播放</span>
  189. </div>
  190. <div class="item">
  191. <img src="images/9.jpg" alt="" />
  192. <h3>
  193. <i>初级</i>
  194. phpStudy极速入门视频教程
  195. </h3>
  196. <span>40W+次播放</span>
  197. </div>
  198. <div class="item">
  199. <img src="images/10.jpg" alt="" />
  200. <h3>
  201. <i>中级</i>
  202. 独孤九贱(4)_PHP视频教程
  203. </h3>
  204. <span>4W+次播放</span>
  205. </div>
  206. <div class="item">
  207. <img src="images/11.jpg" alt="" />
  208. <h3>
  209. <i>中级</i>
  210. 独孤九贱(4)_PHP视频教程
  211. </h3>
  212. <span>50W+次播放</span>
  213. </div>
  214. <div class="item">
  215. <img src="images/12.jpg" alt="" />
  216. <h3>
  217. <i>初级</i>
  218. php完全自学手册
  219. </h3>
  220. <span>20W+次播放</span>
  221. </div>
  222. <div class="item">
  223. <img src="images/13.jpg" alt="" />
  224. <h3>
  225. <i>初级</i>
  226. MySQL权威开发指南(教程
  227. </h3>
  228. <span>2W+次播放</span>
  229. </div>
  230. <div class="item">
  231. <img src="images/14.jpg" alt="" />
  232. <h3>
  233. <i>中级</i>
  234. [公益直播]PHP实战开发极速入门
  235. </h3>
  236. <span>3W+次播放</span>
  237. </div>
  238. </div>
  239. </div>
  240. </body>
  241. </html>

效果如下:

总结:grid布局能快速布局出想要的整体布局,但是完善里面的具体内容需要用的定位等其他知识,增加边框有时候能更好的去布局想要完整实现整个网页布局需要综合掌握html和css的各种知识。多学多练多思考才能不断进步。

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