Blogger Information
Blog 17
fans 0
comment 0
visits 6182
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid常用的容器、项目属性、仿写PHP中文网首页(局部)
生活需要加油
Original
299 people have browsed it

Grid常用的容器、项目属性以及仿写PHP中文网首页(局部)

1. Grid常用的容器与项目属性

1.1 容器属性

  1. display: grid: 容器类型(块或行内)
  2. grid-template-row/columns: 创建显式网格
  3. grid-auto-rows/columns: 创建隐式网格
  4. grid-auto-flow: 项目排列方向
  5. gap: 行列间隙
  6. place-content: 项目在容器中的排列方式
  7. place-items: 项目在单元格中的排列方式

1.2 项目属性

  1. grid-row/column: 某项目占据的网格区域
  2. grid-area: grid-row/column语法糖
  3. place-self: 某项目在单元格中的排列方式
  1. <!DOCTYPE html>
  2. <html lang="en">
  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常用的容器与项目属性</title>
  8. </head>
  9. <body>
  10. <div class="container">
  11. <div class="item">item1</div>
  12. <div class="item">item2</div>
  13. <div class="item">item3</div>
  14. <div class="item">item4</div>
  15. <div class="item">item5</div>
  16. <div class="item active">item6</div>
  17. <div class="item">item7</div>
  18. <div class="item">item8</div>
  19. <div class="item">item9</div>
  20. </div>
  21. </body>
  22. <style>
  23. .container {
  24. width: 450px;
  25. height: 450px;
  26. /* 转为grid网格容器 */
  27. display: grid;
  28. border: 1px solid #000;
  29. /* 1. 显式网格 */
  30. /* grid-template-columns: 100px 100px 100px;
  31. grid-template-rows: 100px 100px 100px; */
  32. grid-template-columns: repeat(3, 100px);
  33. grid-template-rows: repeat(3, 100px);
  34. /* 相同相邻的值可简写 */
  35. /* grid-template-columns: repeat(3, 1fr);
  36. grid-template-rows: repeat(3, 1fr); */
  37. /* 项目排列方向 */
  38. /* grid-auto-flow: column; */
  39. /* gap: 20px 10px; */
  40. place-content: space-evenly;
  41. place-items: start center;
  42. }
  43. .container > .item {
  44. background-color: bisque;
  45. width: 60px;
  46. height: 60px;
  47. }
  48. .container > .item:first-child {
  49. /* 利用span直接表示跨越行(列)数 */
  50. /* grid-area: 1 / 2 / span 2 / span 2; */
  51. }
  52. .container > .item.active {
  53. background-color: lightgreen;
  54. place-self: center end;
  55. }
  56. </style>
  57. </html>

页面效果:

2. 仿写PHP中文网首页:最新课程片断(也可选其它片断)

仿制页面效果如下:

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>job</title>
  8. </head>
  9. <body>
  10. <!-- 整体可看成1行2行 -->
  11. <div class="new-courses">
  12. <div class="top">
  13. <h3>最新课程</h3>
  14. <a href="">更多></a></a>
  15. </div>
  16. <!-- 2行5列 -->
  17. <!-- <div class="courses"> -->
  18. <ul class="courses">
  19. <li class="item">
  20. <a href=""><img src="images/01.jpg" alt="" /></a>
  21. <div class="detail">
  22. <div>
  23. <span>初级</span>
  24. <a href="" target="_blank" title="Laravel 8 课程精讲(台湾同胞版)" class="aBlack">Laravel 8 课程精讲(台湾同胞版)</a>
  25. </div>
  26. <div class="desc">
  27. <span>1234次学习</span>
  28. <span>收藏</span>
  29. </div>
  30. </div>
  31. </li>
  32. <li class="item">
  33. <a href=""><img src="images/02.jpg" alt="" /></a>
  34. <div class="detail">
  35. <div>
  36. <span>初级</span>
  37. <a href="">PHP入门速学(台湾同胞版)</a>
  38. </div>
  39. <div class="desc">
  40. <span>1234次学习</span>
  41. <span>收藏</span>
  42. </div>
  43. </div>
  44. </li>
  45. <li class="item">
  46. <a href=""><img src="images/03.jpg" alt="" /></a>
  47. <div class="detail">
  48. <div>
  49. <span>初级</span>
  50. <a href="">Apipost从入门到精通</a>
  51. </div>
  52. <div class="desc">
  53. <span>1234次学习</span>
  54. <span>收藏</span>
  55. </div>
  56. </div>
  57. </li><li class="item">
  58. <a href=""><img src="images/04.png" alt="" /></a>
  59. <div class="detail">
  60. <div>
  61. <span>初级</span>
  62. <a href="">Apipost从入门到精通</a>
  63. </div>
  64. <div class="desc">
  65. <span>1234次学习</span>
  66. <span>收藏</span>
  67. </div>
  68. </div>
  69. </li><li class="item">
  70. <a href=""><img src="images/05.jpg" alt="" /></a>
  71. <div class="detail">
  72. <div>
  73. <span>初级</span>
  74. <a href="">帝国CMS企业仿站教程</a>
  75. </div>
  76. <div class="desc">
  77. <span>1234次学习</span>
  78. <span>收藏</span>
  79. </div>
  80. </div>
  81. </li><li class="item">
  82. <a href=""><img src="images/06.jpg" alt="" /></a>
  83. <div class="detail">
  84. <div>
  85. <span>初级</span>
  86. <a href="">WordPress零基础新手搭建个人博客及企业网站</a>
  87. </div>
  88. <div class="desc">
  89. <span>1234次学习</span>
  90. <span>收藏</span>
  91. </div>
  92. </div>
  93. </li><li class="item">
  94. <a href=""><img src="images/07.jpg" alt="" /></a>
  95. <div class="detail">
  96. <div>
  97. <span>初级</span>
  98. <a href="">极致CMS零基础建站教学视频</a>
  99. </div>
  100. <div class="desc">
  101. <span>1234次学习</span>
  102. <span>收藏</span>
  103. </div>
  104. </div>
  105. </li><li class="item">
  106. <a href=""><img src="images/08.jpg" alt="" /></a>
  107. <div class="detail">
  108. <div>
  109. <span>初级</span>
  110. <a href="">前端项目-尚优选【HTML/CSS/JS技术综合实战】
  111. </a>
  112. </div>
  113. <div class="desc">
  114. <span>1234次学习</span>
  115. <span>收藏</span>
  116. </div>
  117. </div>
  118. </li><li class="item">
  119. <a href=""><img src="images/09.jpg" alt="" /></a>
  120. <div class="detail">
  121. <div>
  122. <span>初级</span>
  123. <a href="">Vue3.0从0到搭建通用后台管理系统项目实战</a>
  124. </div>
  125. <div class="desc">
  126. <span>1234次学习</span>
  127. <span>收藏</span>
  128. </div>
  129. </div>
  130. </li><li class="item">
  131. <a href=""><img src="images/10.jpg" alt="" /></a>
  132. <div class="detail">
  133. <div>
  134. <span>初级</span>
  135. <a href="">零基础前端课程【Vue进阶学习及实战应用】</a>
  136. </div>
  137. <div class="desc">
  138. <span>1234次学习</span>
  139. <span>收藏</span>
  140. </div>
  141. </div>
  142. </li>
  143. </ul>
  144. <!-- </div> -->
  145. </div>
  146. <style>
  147. * {
  148. margin: 0;
  149. padding: 0;
  150. box-sizing: border-box;
  151. }
  152. body{
  153. background-color: #F2F5F7;
  154. }
  155. body a{
  156. color: #555;
  157. text-decoration: none;
  158. }
  159. .new-courses {
  160. width: 1200px;
  161. margin: auto;
  162. display: grid;
  163. grid-template-rows: 75px 530px;
  164. grid-template-columns: repeat(1, 1fr);
  165. gap:10px;
  166. }
  167. .top {
  168. width: 1200px;
  169. height: 75px;
  170. display: grid;
  171. grid-template-rows: repeat(1, 1fr);
  172. grid-template-columns: repeat(2, 1fr);
  173. place-content: space-between;
  174. place-items: center;
  175. }
  176. .top>:first-child{
  177. place-self: center start;
  178. }
  179. .top a {
  180. place-self: center end;
  181. padding:10px 20px;
  182. }
  183. .top a:hover {
  184. cursor: pointer;
  185. background-color: red;
  186. border-radius: 10px;
  187. color: white;
  188. transition: 0.5s;
  189. }
  190. .courses{
  191. display: grid;
  192. grid-template-rows: repeat(2,1fr);
  193. grid-template-columns: repeat(5,1fr);
  194. gap: 30px 20px;
  195. }
  196. .courses .detail{
  197. padding:10px;
  198. }
  199. .courses li.item{
  200. /* width: 330px; */
  201. height: 250px;
  202. list-style: none;
  203. border-radius: 10px;
  204. background-color:white;
  205. display: flex;
  206. flex-flow: column nowrap;
  207. }
  208. .courses li.item a{
  209. border-radius: 10px 10px 0 0;
  210. overflow: hidden;
  211. }
  212. .courses li.item a img{
  213. width: 224px;
  214. object-fit: fill;
  215. overflow: hidden;
  216. }
  217. .courses li.item a img:hover{
  218. transform: scale(1.1);
  219. }
  220. .courses li.item .detail div{
  221. height: 75px;
  222. }
  223. .courses li.item .detail div:first-child span{
  224. display: inline-block;
  225. padding:2px 4px;
  226. background-color: #DFE8FC;
  227. font-size: 11px;
  228. }
  229. .courses li.item .detail a{
  230. display: inline;
  231. font-size: 14px;
  232. text-decoration: none;
  233. }
  234. .courses li.item .detail .desc{
  235. height: 30px;
  236. display: flex;
  237. flex-flow: row nowrap;
  238. place-content: space-between;
  239. }
  240. </style>
  241. </body>
  242. </html>

3. 总结:

grid布局运用起来确实方便,功能更强大,老师总结后属性已经相对简单!。

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!