博客列表 >实例演示Grid常用的容器与项目属性与仿写PHP中文网首页:最新课程片断(也可选其它片断)

实例演示Grid常用的容器与项目属性与仿写PHP中文网首页:最新课程片断(也可选其它片断)

alexcy的学习博客
alexcy的学习博客原创
2023年02月10日 17:22:22271浏览

1.实例演示Grid常用的容器与项目属性

  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>Document</title>
  8. </head>
  9. <body>
  10. <div class="wrapper">
  11. <div class="box"></div>
  12. </div>
  13. <style>
  14. .wrapper {
  15. display: grid;
  16. width: 500px;
  17. height: 200px;
  18. grid-template-columns: 150px 200px 150px;
  19. grid-template-rows:repeat(3,1fr);
  20. }
  21. .box {
  22. background-color: coral;
  23. }
  24. .box:first-child{
  25. grid-area: 1 / 2 / span 2 / span 2;
  26. }
  27. </style>
  28. </body>
  29. </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>Document</title>
  8. </head>
  9. <body>
  10. <div class="wrapper">
  11. <div class="box">盒子1</div>
  12. <div class="box">盒子2</div>
  13. <div class="box">盒子3</div>
  14. <div class="box">盒子4</div>
  15. <div class="box">盒子5</div>
  16. <div class="box">盒子6</div>
  17. <div class="box">盒子7</div>
  18. <div class="box">盒子8</div>
  19. <div class="box">盒子9</div>
  20. <div class="box add">盒子10</div>
  21. <div class="box add">盒子11</div>
  22. </div>
  23. <style>
  24. .wrapper {
  25. display: grid;
  26. width: 500px;
  27. min-height: 200px;
  28. grid-template-columns: 150px 200px 150px;
  29. grid-template-rows:repeat(3,1fr);
  30. grid-auto-flow: row;
  31. grid-auto-rows: 50px;
  32. }
  33. .box {
  34. background-color: coral;
  35. }
  36. .box.add{
  37. background-color: pink;
  38. }
  39. </style>
  40. </body>
  41. </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>Document</title>
  8. </head>
  9. <body>
  10. <div class="wrapper">
  11. <div class="box">盒子1</div>
  12. <div class="box">盒子2</div>
  13. <div class="box">盒子3</div>
  14. <div class="box">盒子4</div>
  15. <div class="box">盒子5</div>
  16. <div class="box">盒子6</div>
  17. <div class="box">盒子7</div>
  18. <div class="box">盒子8</div>
  19. <div class="box">盒子9</div>
  20. </div>
  21. <style>
  22. .wrapper {
  23. display: grid;
  24. width: 600px;
  25. height: 300px;
  26. border: 1px solid #000;
  27. background-color: lavender;
  28. grid-template-columns: 150px 200px 150px;
  29. grid-template-rows:repeat(3,70px);
  30. place-content:space-around;
  31. place-items: center;
  32. }
  33. .box {
  34. background-color: coral;
  35. }
  36. </style>
  37. </body>
  38. </html>

效果图:

2.仿写PHP中文网首页

  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>Document</title>
  8. <style>
  9. *{
  10. padding: 0;margin: 0;
  11. }
  12. a {
  13. text-decoration: none;
  14. color: #999999;
  15. font-size: 14px;
  16. }
  17. body {
  18. background-color: #f3f5f7;
  19. }
  20. .new {
  21. margin: 0 auto;
  22. display: grid;
  23. width: 1200px;
  24. grid-template-rows: 100px ;
  25. }
  26. .bd{
  27. display: grid;
  28. place-content: center space-between;
  29. grid-template-columns: 100px 100px;
  30. place-items:center;
  31. }
  32. .new .bd h2{
  33. font-weight: bold;
  34. font-size: 22px;
  35. color: #333;
  36. }
  37. .bd a{
  38. padding: 5px 20px;
  39. border-radius: 30px;
  40. background-color: rgb(235, 235, 235);
  41. opacity: .8;
  42. transition: all .5;
  43. }
  44. .bd a:hover{
  45. background-color: red;
  46. color: #fff;
  47. }
  48. .hd ul{
  49. display: grid;
  50. grid-template-columns: 224px 224px 224px 224px 224px;
  51. grid-template-rows: 235px 235px;
  52. gap: 20px;
  53. }
  54. .hd .list .item img{
  55. width: 224px;
  56. height: 130px;
  57. }
  58. .hd ul li {
  59. width: 224px;
  60. background-color: #fff;
  61. border-radius: 10px;
  62. overflow: hidden;
  63. }
  64. .hd ul li .nr{
  65. padding: 20px 10px;
  66. }
  67. .hd ul li .nr .title {
  68. display: grid;
  69. place-content: center space-between ;
  70. grid-template-columns: 50px 1fr;
  71. place-items: center;
  72. }
  73. .title a{
  74. color: #000;
  75. }
  76. .hd ul li .nr .title span {
  77. background-color:#E0E8FC;
  78. color: #298AFD;
  79. padding: 1px 4px;
  80. border-radius: 2px;
  81. }
  82. .hd ul li .nr .desc {
  83. display: flex;
  84. place-content:space-between ;
  85. grid-template-columns: 1fr 1fr;
  86. margin-top: 25px;
  87. font-size: 12px;
  88. color: #b7b7b7;
  89. padding:0 5px;
  90. }
  91. </style>
  92. </head>
  93. <body>
  94. <div class="new">
  95. <div class="bd">
  96. <h2>最新课程</h2>
  97. <a href="#">更多></a>
  98. </div>
  99. <div class="hd">
  100. <ul class="list">
  101. <li class="item">
  102. <a href="#"><img src="pic.jpg" alt=""></a>
  103. <div class="nr">
  104. <div class="title">
  105. <span>初级</span>
  106. <a href="#">课程标题课程标题</a>
  107. </div>
  108. <div class="desc">
  109. <span>1234次学习</span>
  110. <span>收藏</span>
  111. </div>
  112. </div>
  113. </li>
  114. <li class="item">
  115. <a href="#"><img src="pic.jpg" alt=""></a>
  116. <div class="nr">
  117. <div class="title">
  118. <span>初级</span>
  119. <a href="#">课程标题课程标题</a>
  120. </div>
  121. <div class="desc">
  122. <span>1234次学习</span>
  123. <span>收藏</span>
  124. </div>
  125. </div>
  126. </li>
  127. <li class="item">
  128. <a href="#"><img src="pic.jpg" alt=""></a>
  129. <div class="nr">
  130. <div class="title">
  131. <span>初级</span>
  132. <a href="#">课程标题课程标题</a>
  133. </div>
  134. <div class="desc">
  135. <span>1234次学习</span>
  136. <span>收藏</span>
  137. </div>
  138. </div>
  139. </li>
  140. <li class="item">
  141. <a href="#"><img src="pic.jpg" alt=""></a>
  142. <div class="nr">
  143. <div class="title">
  144. <span>初级</span>
  145. <a href="#">课程标题课程标题</a>
  146. </div>
  147. <div class="desc">
  148. <span>1234次学习</span>
  149. <span>收藏</span>
  150. </div>
  151. </div>
  152. </li>
  153. <li class="item">
  154. <a href="#"><img src="pic.jpg" alt=""></a>
  155. <div class="nr">
  156. <div class="title">
  157. <span>初级</span>
  158. <a href="#">课程标题课程标题</a>
  159. </div>
  160. <div class="desc">
  161. <span>1234次学习</span>
  162. <span>收藏</span>
  163. </div>
  164. </div>
  165. </li>
  166. <li class="item">
  167. <a href="#"><img src="pic.jpg" alt=""></a>
  168. <div class="nr">
  169. <div class="title">
  170. <span>初级</span>
  171. <a href="#">课程标题课程标题</a>
  172. </div>
  173. <div class="desc">
  174. <span>1234次学习</span>
  175. <span>收藏</span>
  176. </div>
  177. </div>
  178. </li>
  179. <li class="item">
  180. <a href="#"><img src="pic.jpg" alt=""></a>
  181. <div class="nr">
  182. <div class="title">
  183. <span>初级</span>
  184. <a href="#">课程标题课程标题</a>
  185. </div>
  186. <div class="desc">
  187. <span>1234次学习</span>
  188. <span>收藏</span>
  189. </div>
  190. </div>
  191. </li>
  192. <li class="item">
  193. <a href="#"><img src="pic.jpg" alt=""></a>
  194. <div class="nr">
  195. <div class="title">
  196. <span>初级</span>
  197. <a href="#">课程标题课程标题</a>
  198. </div>
  199. <div class="desc">
  200. <span>1234次学习</span>
  201. <span>收藏</span>
  202. </div>
  203. </div>
  204. </li>
  205. <li class="item">
  206. <a href="#"><img src="pic.jpg" alt=""></a>
  207. <div class="nr">
  208. <div class="title">
  209. <span>初级</span>
  210. <a href="#">课程标题课程标题</a>
  211. </div>
  212. <div class="desc">
  213. <span>1234次学习</span>
  214. <span>收藏</span>
  215. </div>
  216. </div>
  217. </li>
  218. <li class="item">
  219. <a href="#"><img src="pic.jpg" alt=""></a>
  220. <div class="nr">
  221. <div class="title">
  222. <span>初级</span>
  223. <a href="#">课程标题课程标题</a>
  224. </div>
  225. <div class="desc">
  226. <span>1234次学习</span>
  227. <span>收藏</span>
  228. </div>
  229. </div>
  230. </li>
  231. </ul>
  232. </div>
  233. </div>
  234. </body>
  235. </html>

效果图:

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