Blogger Information
Blog 16
fans 0
comment 1
visits 5764
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid常用的容器与项目属性 仿写PHP中文网首页:最新课程片断(也可选其它片断)
P粉890456325
Original
313 people have browsed it

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

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. <style>
  9. .container0 {
  10. width: 300px;
  11. height: 150px;
  12. /* 转为grid网格容器 */
  13. display: grid;
  14. /* 任务: 创建一个3行3列的容器 */
  15. /* 1. 显式网格 */
  16. /* grid-template-columns: 100px 100px 100px;
  17. grid-template-rows: 50px 50px 50px; */
  18. /* 对于相同且相邻的值,可以用repeat()简化 */
  19. /* grid-template-columns: repeat(3, 100px);
  20. grid-template-rows: repeat(3, 50px); */
  21. /* 宽度300px,分3份,每1份肯定是100px */
  22. /* 新单位: fr, 比例 */
  23. grid-template-columns: repeat(3, 1fr);
  24. grid-template-rows: repeat(3, 1fr);
  25. }
  26. /* grid容器的项目: 容器的子元素 */
  27. .container0 > .item0 {
  28. background-color: bisque;
  29. }
  30. .container0 > .item0:first-child {
  31. /* 默认位置 */
  32. /* grid-row-start: 1;
  33. grid-row-end: 2;
  34. 行开始与行结束
  35. */
  36. /* grid-row: 1 / 2; 行合并写法*/
  37. /* grid-column-start: 1;
  38. grid-column-end: 2;
  39. 列开始与列结束
  40. */
  41. /* grid-column: 1 / 2; *行合并写法/
  42. /* grid-row/column: 行(列)起始编号 / 行(列)结束编号 */
  43. /* 可以将项目移动到容器空间的任意位置上 */
  44. /* 正中间 */
  45. /* grid-row: 2 / 3;
  46. grid-column: 2 / 3; */
  47. /* 一个项目至少要占据一个单元格,一个单元格,默认跨越1行1列 */
  48. /*简化写法
  49. grid-row: 2;
  50. grid-column: 2; */
  51. /* 从正中间,跨越2行2列,如何布局 */
  52. /* grid-row: 2 / 4;
  53. grid-column: 2 / 4; */
  54. /* 当单元格跨越多个时,形成一个矩形的空间,称为"网格区域" */
  55. /* 只关心跨越几行几列,至于结束的行号和列号并不关心 */
  56. /* grid-row: 2 / span 2;
  57. grid-column: 2 / span 2; */
  58. /* span跨越多行多列可形成一个网格区域,使用以上的2个属性,可以简化以上的操作 */
  59. /* area区域的意思 grid-area: 行开始 / 列开始 / 行结束 / 列结束 */
  60. /* grid-area: 2 / 2 / 4 / 4; */
  61. /* 向上一行 */
  62. /* grid-area: 1 / 2 / 3 / 4; */
  63. grid-area: 1 / 2 / span 2 / span 2;
  64. /* 当前,如果是 span 1 可以简化,如果span 1不在最后的位置不能省 */
  65. }
  66. </style>
  67. </head>
  68. <body>
  69. <div class="container1">
  70. <div class="item1">item1</div>
  71. </div>
  72. <hr>
  73. <style>
  74. .container1{
  75. width: 300px;
  76. height: 150px;
  77. display: grid;
  78. grid-template-columns: repeat(3,1fr);
  79. grid-template-rows: repeat(3,1fr);
  80. }
  81. .container1 >.item1{
  82. background-color: red;
  83. }
  84. .container1>.item1:first-child{
  85. grid-area: 3/2/span 2/span 2;
  86. }
  87. </style>
  88. <hr>
  89. <div class="container">
  90. <div class="item">item1</div>
  91. <div class="item">item2</div>
  92. <div class="item">item3</div>
  93. <div class="item">item4</div>
  94. <div class="item">item5</div>
  95. <div class="item">item6</div>
  96. <div class="item">item7</div>
  97. <div class="item">item8</div>
  98. <div class="item">item9</div>
  99. <!-- 当前容器有9个单元格,默认可以放入9个项目 -->
  100. <!-- 如果项目数量 > 9, 会什么 -->
  101. <div class="item add">item10</div>
  102. <div class="item add">item11</div>
  103. </div>
  104. <style>
  105. .container {
  106. width: 300px;
  107. height: 300px;
  108. padding: 5px;
  109. background-color: antiquewhite;
  110. border: 1px solid forestgreen;
  111. display: grid;
  112. /* 显式网格 */
  113. grid-template-columns: repeat(3, 1fr);
  114. grid-template-rows: repeat(3, 1fr);
  115. /* 1. 排列规则 */
  116. /* row: 行优先,默认值 */
  117. /* grid-auto-flow: row; */
  118. /* grid-auto-flow: column; */
  119. /* 2. 隐式网格 */
  120. /* 超出显式网格数量的项目,创建在隐式网格中(自动生成) */
  121. /* grid-auto-rows: 50px; */
  122. /* grid-auto-rows: 1fr; */
  123. /* gap: 行列间隙/轨道间距 */
  124. /* gap: 垂直方向 水平方向 */
  125. /* gap:5px 5px;
  126. gap: 10px 5px;
  127. gap: 10px 10px; */
  128. gap: 5px;
  129. }
  130. /* 项目*/
  131. .container > .item {
  132. background-color: bisque;
  133. }
  134. .container > .item.add {
  135. background-color: violet;
  136. /* 如果是行优先,高度就是默认的内容高度 */
  137. }
  138. </style>
  139. <hr>
  140. <hr>
  141. <div class="container2">
  142. <div class="item2">item1</div>
  143. <div class="item2">item2</div>
  144. <div class="item2">item3</div>
  145. <div class="item2">item4</div>
  146. <div class="item2 active">item5</div>
  147. <div class="item2">item6</div>
  148. <div class="item2">item7</div>
  149. <div class="item2">item8</div>
  150. <div class="item2">item9</div>
  151. </div>
  152. <style>
  153. .container2 {
  154. /* width: 300px;
  155. height: 300px; */
  156. width: 450px;
  157. height: 450px;
  158. border: 1px solid #000;
  159. background-color: lightcyan;
  160. display: grid;
  161. /* 显式网格 */
  162. grid-template-columns: repeat(3, 100px);
  163. grid-template-rows: repeat(3, 100px);
  164. /*
  165. 1. 对齐前提: 容器中必须存在"剩余空间"(待分配的空间)
  166. 2. 对齐本质: 剩余空间,在"项目"之间的分配方案
  167. 3. 剩余空间: Flex(主轴,交叉轴), Grid(容器,单元格)
  168. */
  169. /* 1. 项目在"容器"中的对齐 */
  170. /* place-content: 垂直方向 水平方向; */
  171. /* 默认左上角,行与列的起始编号 */
  172. place-content: start start;
  173. /* 垂直居中,水平居右 */
  174. place-content: center end;
  175. /* 垂直,水平全居中 */
  176. /* place-content: center center; */
  177. /* 双值相同, 可只写一个 */
  178. place-content: center;
  179. /* 剩余空间还可以在所有项目之间进行分配 */
  180. place-content: space-between space-around;
  181. place-content: space-between space-between;
  182. place-content: space-between;
  183. place-content: space-around;
  184. /* 2. 项目在"单元格"中的对齐 */
  185. /* place-items: 垂直方向 水平方向; */
  186. place-items: start start;
  187. place-items: start end;
  188. place-items: center center;
  189. place-items: center;
  190. place-items: end;
  191. place-items: start;
  192. /* position: relative; */
  193. }
  194. /* 项目*/
  195. .container2 > .item2 {
  196. background-color: bisque;
  197. /* 默认,项目会充满单元格 */
  198. width: 50px;
  199. height: 50px;
  200. /* 传统margin */
  201. /* 要求 5px 间隙 */
  202. /* margin: 5px; */
  203. /* margin-right: 5px;
  204. margin-bottom: 5px; */
  205. }
  206. .container2 > .item2.active {
  207. background-color: violet;
  208. /* 某个项目,有特殊的对齐要求 */
  209. place-self: end;
  210. place-self: center;
  211. /* position: relative;
  212. top: 10px;
  213. left: 10px; */
  214. /* position: absolute;
  215. top: 0;
  216. left: 0; */
  217. }
  218. </style>
  219. </body>
  220. </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. <style>
  9. *{
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. body{
  15. background-color: gainsboro;
  16. }
  17. ul li{
  18. list-style: none;
  19. }
  20. a{
  21. text-decoration: none;
  22. color: rgb(0,0,0);
  23. }
  24. a:hover{
  25. cursor: pointer;
  26. color:blanchedalmond;
  27. }
  28. .new-courses{
  29. width: 1200px;
  30. margin: 130px auto;
  31. display: grid;
  32. grid-template-columns: 30px 530px;
  33. }
  34. .top{
  35. width: 1198px;
  36. height: 30px;
  37. display: grid;
  38. grid-template-columns: 150px 100px;
  39. place-content: space-between;
  40. /* margin-left: 30px; */
  41. place-items: center;
  42. }
  43. .top h3{
  44. font-size: 20px;
  45. line-height: 20px;
  46. /* margin-left: 30px; */
  47. }
  48. .top a{
  49. width: 70px;
  50. height:25px;
  51. line-height: 25px;
  52. font-size: 14px;
  53. text-align: center;
  54. place-self: end;
  55. margin-right: 15px;
  56. background-color: whitesmoke;
  57. }
  58. .top a:hover{
  59. background-color: lightcoral;
  60. color: white;
  61. border-radius: 15px;
  62. }
  63. /* 课程内容grid,2行5列 */
  64. .courses > .list {
  65. width: 1180px;
  66. display: grid;
  67. grid-template-columns: repeat(5,220px);
  68. grid-template-rows: repeat(2,280px);
  69. place-content: space-between;
  70. margin-top: 60px;
  71. }
  72. /* 一个课程grid,2行1列 */
  73. .courses > .list > .item {
  74. display: grid;
  75. grid-template-rows: 150px 100px;
  76. }
  77. .courses > .list > .item a{
  78. width: 220px;
  79. overflow: hidden;
  80. border-radius: 15px 15px 0 0;
  81. }
  82. .courses > .list > .item a:hover{
  83. color: red;
  84. }
  85. .courses > .list > .item a img{
  86. width: 220px;
  87. height: 150px;
  88. transition: all 0.5s;
  89. }
  90. .courses > .list > .item a img:hover{
  91. width: 220px;
  92. overflow: hidden;
  93. transform: scale(1.1);
  94. }
  95. /* 文字内容grid,2行1列 */
  96. .courses > .list > .item > .detail{
  97. display: grid;
  98. grid-template-rows: 60px 40px;
  99. font-size: 14px;
  100. place-items: center;
  101. border-radius: 0 0 15px 15px;
  102. background-color: white;
  103. }
  104. .courses > .list > .item > .detail > .title > .level{
  105. padding:0 10px;
  106. background-color: #E0E8FC;
  107. color:#298AFD;
  108. }
  109. .courses > .list > .item > .detail > .title > .level.add{
  110. padding:0 10px;
  111. background-color: #ef9fc7a4;
  112. color:#fd2942;
  113. }
  114. .courses > .list > .item > .detail > .title {
  115. place-self: end;
  116. padding: 0 25px;
  117. }
  118. /* grid,1行2列 */
  119. .courses > .list > .item > .detail > .desc{
  120. display: grid;
  121. grid-template-columns: 100px 100px;
  122. font-size: 10px;
  123. }
  124. .courses > .list > .item > .detail > .desc span{
  125. padding-left: 20px;
  126. color:gray
  127. }
  128. .courses > .list > .item > .detail > .desc span:last-child{
  129. padding-right: 20px;
  130. place-self: end;
  131. }
  132. </style>
  133. </head>
  134. <body>
  135. <!-- 整体可看成1行2行 -->
  136. <div class="new-courses">
  137. <div class="top">
  138. <h3>最新课程</h3>
  139. <a href="">更多 ></a>
  140. </div>
  141. <div class="courses">
  142. <ul class="list">
  143. <!--1个课程开始-->
  144. <li class="item">
  145. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  146. <div class="detail">
  147. <div class="title">
  148. <span class="level">初级</span>
  149. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  150. </div>
  151. <div class="desc">
  152. <span>1234次学习</span>
  153. <span>收藏</span>
  154. </div>
  155. </div>
  156. </li>
  157. <li class="item">
  158. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  159. <div class="detail">
  160. <div class="title">
  161. <span class="level">初级</span>
  162. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  163. </div>
  164. <div class="desc">
  165. <span>1234次学习</span>
  166. <span>收藏</span>
  167. </div>
  168. </div>
  169. </li>
  170. <li class="item">
  171. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  172. <div class="detail">
  173. <div class="title">
  174. <span class="level add">中级</span>
  175. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  176. </div>
  177. <div class="desc">
  178. <span>1234次学习</span>
  179. <span>收藏</span>
  180. </div>
  181. </div>
  182. </li>
  183. <li class="item">
  184. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  185. <div class="detail">
  186. <div class="title">
  187. <span class="level">初级</span>
  188. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  189. </div>
  190. <div class="desc">
  191. <span>1234次学习</span>
  192. <span>收藏</span>
  193. </div>
  194. </div>
  195. </li>
  196. <li class="item">
  197. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  198. <div class="detail">
  199. <div class="title">
  200. <span class="level">初级</span>
  201. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  202. </div>
  203. <div class="desc">
  204. <span>1234次学习</span>
  205. <span>收藏</span>
  206. </div>
  207. </div>
  208. </li> <li class="item">
  209. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  210. <div class="detail">
  211. <div class="title">
  212. <span class="level">初级</span>
  213. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  214. </div>
  215. <div class="desc">
  216. <span>1234次学习</span>
  217. <span>收藏</span>
  218. </div>
  219. </div>
  220. </li> <li class="item">
  221. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  222. <div class="detail">
  223. <div class="title">
  224. <span class="level">初级</span>
  225. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  226. </div>
  227. <div class="desc">
  228. <span>1234次学习</span>
  229. <span>收藏</span>
  230. </div>
  231. </div>
  232. </li> <li class="item">
  233. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  234. <div class="detail">
  235. <div class="title">
  236. <span class="level">初级</span>
  237. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  238. </div>
  239. <div class="desc">
  240. <span>1234次学习</span>
  241. <span>收藏</span>
  242. </div>
  243. </div>
  244. </li> <li class="item">
  245. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  246. <div class="detail">
  247. <div class="title">
  248. <span class="level">初级</span>
  249. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  250. </div>
  251. <div class="desc">
  252. <span>1234次学习</span>
  253. <span>收藏</span>
  254. </div>
  255. </div>
  256. </li>
  257. <li class="item">
  258. <a href=""><img src="https://img.php.cn/upload/course/000/000/068/63e202276944f543.jpg" alt=""></a>
  259. <div class="detail">
  260. <div class="title">
  261. <span class="level add">中级</span>
  262. <a href="">Laravel 8 课程精讲(台湾同胞版)</a>
  263. </div>
  264. <div class="desc">
  265. <span>1234次学习</span>
  266. <span>收藏</span>
  267. </div>
  268. </div>
  269. </li>
  270. <!--1个课程结束-->
  271. </ul>
  272. </div>
  273. </div>
  274. </body>
  275. </html>
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!