博客列表 >Grid常用的容器与项目属性

Grid常用的容器与项目属性

vbokok
vbokok原创
2023年02月12日 21:11:18276浏览
  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>grid属性</title>
  8. </head>
  9. <body>
  10. <div class="container">
  11. <div class="item">item1</div>
  12. </div>
  13. <hr/>
  14. <style>
  15. .container {
  16. display: grid;
  17. width: 200px;
  18. height: 150px;
  19. grid-template-columns: repeat(3, 1fr);
  20. grid-template-rows: repeat(3, 1fr)
  21. }
  22. .container .item {
  23. background-color: yellowgreen;
  24. grid-area: 1 /2 / span 2 / span 2;
  25. }
  26. </style>
  27. <div class="container1">
  28. <div class="item">item1</div>
  29. <div class="item">item2</div>
  30. <div class="item">item3</div>
  31. <div class="item">item4</div>
  32. <div class="item">item5</div>
  33. <div class="item">item6</div>
  34. <div class="item">item7</div>
  35. <div class="item">item8</div>
  36. <div class="item">item9</div>
  37. <div class="item one">item10</div>
  38. <div class="item one">item11</div>
  39. </div>
  40. <hr />
  41. <style>
  42. .container1 {
  43. display: grid;
  44. width: 200px;
  45. height: 150px;
  46. grid-template-columns: repeat(3, 1fr);
  47. grid-template-rows: repeat(3, 1fr);
  48. grid-auto-flow: row;
  49. grid-auto-rows: 1fr;
  50. }
  51. .container1 > .item {
  52. background-color: seagreen;
  53. }
  54. .container1 > .item.one {
  55. background-color: violet;
  56. }
  57. </style>
  58. <div class="container2">
  59. <div class="item">item1</div>
  60. <div class="item">item2</div>
  61. <div class="item">item3</div>
  62. <div class="item">item4</div>
  63. <div class="item">item5</div>
  64. <div class="item">item6</div>
  65. <div class="item active">item7</div>
  66. <div class="item">item8</div>
  67. <div class="item">item9</div>
  68. </div>
  69. <hr />
  70. <style>
  71. .container2 {
  72. display: grid;
  73. width: 250px;
  74. height: 250px;
  75. background-color:khaki;
  76. border: 1px solid black;
  77. grid-template-columns: repeat(3, 70px);
  78. grid-template-rows: repeat(3, 70px);
  79. /* place-content: center; */
  80. /* place-content: space-between; */
  81. place-content: space-around;
  82. place-items: center;
  83. }
  84. .container2 > .item {
  85. background-color:aquamarine;
  86. width: 50px;
  87. height: 50px;
  88. }
  89. .container2 > .item.active {
  90. background-color: brown;
  91. place-self: end start;
  92. }
  93. </style>
  94. <div class="container3">
  95. <div class="item">item1</div>
  96. <div class="item">item2</div>
  97. <div class="item">item3</div>
  98. <div class="item">item4</div>
  99. <div class="item">item5</div>
  100. <div class="item">item6</div>
  101. <div class="item">item7</div>
  102. <div class="item">item8</div>
  103. <div class="item">item9</div>
  104. </div>
  105. <style>
  106. .container3 {
  107. display: grid;
  108. width: 210px;
  109. height: 210px;
  110. background-color:khaki;
  111. border: 1px solid black;
  112. grid-template-columns: repeat(3, 1fr);
  113. grid-template-rows: repeat(3, 1fr);
  114. gap: 10px;
  115. }
  116. .container3 > .item {
  117. background-color:aquamarine;
  118. }
  119. </style>
  120. </body>
  121. </html>

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