Blogger Information
Blog 37
fans 0
comment 0
visits 14219
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
9个grid属性,并详解每个属性的用途
秋闲独醉
Original
278 people have browsed it

9个grid属性,并详解每个属性的用途

  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. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. background-color: brown;
  14. }
  15. html {
  16. font-size: 16px;
  17. }
  18. div.container {
  19. /* 设置container容器的大小和颜色 */
  20. width: 20rem;
  21. height: 20rem;
  22. background-color: green;
  23. /* 创建grid风格容器 */
  24. display: grid;
  25. /* 画表格 */
  26. /* 画行 */
  27. /* grid-template-rows: 5rem 5rem 5rem; */
  28. grid-template-rows: repeat(3, 5rem);
  29. /* 画例 */
  30. /* grid-template-columns: 5rem 5rem 5rem; */
  31. grid-template-columns: repeat(3, 5rem);
  32. /* 单元格方向 */
  33. /* 主轴方向 */
  34. grid-auto-flow: row;
  35. /* 交叉轴方向 */
  36. /* grid-auto-flow: column; */
  37. /* 多的单元格放入那里 */
  38. grid-auto-columns: 5rem;
  39. /* grap 行间距 列间距 */
  40. gap: 1rem 1rem;
  41. /* grip容器的对齐方式 */
  42. /* 垂直 水平对齐 */
  43. place-content: center;
  44. place-content: start center;
  45. place-content: start start;
  46. place-content: center start;
  47. place-content: end end;
  48. /* 剩余空间分配 */
  49. place-content: space-between;
  50. place-content: space-between space-around;
  51. place-content: space-between space-evenly;
  52. /* 项目在单元中的对齐方式 */
  53. /* 先对单元内容缩小 */
  54. place-items: center;
  55. place-items: start start;
  56. place-items: end end;
  57. place-items: start center;
  58. place-items: center;
  59. }
  60. /* 奇数的单元格颜色 */
  61. div.item:nth-of-type(odd) {
  62. background-color: yellow;
  63. }
  64. /* 偶数的单元格颜色 */
  65. div.item:nth-of-type(2n) {
  66. background-color: blue;
  67. }
  68. /* 对单元内容缩小 */
  69. div.item {
  70. width: 3rem;
  71. height: 3rem;
  72. }
  73. /* 对个别单元格位置调整 */
  74. div.item:nth-last-of-type(-n + 3) {
  75. place-self: end center;
  76. }
  77. </style>
  78. </head>
  79. <body>
  80. <div class="container">
  81. <div class="item">1</div>
  82. <div class="item">2</div>
  83. <div class="item">3</div>
  84. <div class="item">4</div>
  85. <div class="item">5</div>
  86. <div class="item">6</div>
  87. <div class="item">7</div>
  88. <div class="item">8</div>
  89. <div class="item">9</div>
  90. <!-- 多出来的单元 -->
  91. <!-- <div class="item">10</div> -->
  92. </div>
  93. </body>
  94. </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!