Blogger Information
Blog 25
fans 0
comment 0
visits 10605
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示隐式网格,对齐方式,行列间隙
PHui
Original
367 people have browsed it

一.隐式网格

  1. <body>
  2. <div class="container">
  3. <div class="item">item1</div>
  4. <div class="item">item2</div>
  5. <div class="item">item3</div>
  6. <div class="item">item4</div>
  7. <div class="item">item5</div>
  8. <div class="item">item6</div>
  9. <div class="item">item7</div>
  10. <div class="item">item8</div>
  11. <div class="item">item9</div>
  12. <!-- 再添加两个项目 -->
  13. <div class="item">item10</div>
  14. <div class="item">item11</div>
  15. </div>
  16. <style>
  17. .container {
  18. width: 300px;
  19. height: 150px;
  20. display: grid;
  21. /* 显示网格 */
  22. grid-template-rows: repeat(3, 1fr);
  23. grid-template-columns: repeat(3, 1fr);
  24. /* 隐式网格 */
  25. /* 多余的项目,出现在隐式网格中(自动生成) */
  26. /* 默认项目行排列,设置隐式空间行高,与显示空间的规格保持一致 */
  27. grid-auto-rows: 1fr;
  28. }
  29. .container > .item {
  30. background-color: #ccc;
  31. }
  32. </style>
  33. </body>

二.对齐方式

1.项目在”容器”中的对齐

  1. place-content: 垂直方向 水平方向
  2. 默认值: 垂直居上, 水平居左
  3. place-content: start start;

  1. place-content: center centert;

  1. place-content: space-around space-around;


对齐的值为:start,end,center,space-around,space-between,space-evenly

2.项目在”单元格”中的对齐

  1. 单元格中必须要有剩余空间, 即: 项目 < 单元格
  2. place-items: 垂直方向 水平方向
  3. place-items: start start;

  1. place-items: center center;


对齐的值为:start,end,center

3. 设置某个项目在单元格对齐方式(与众不同)

  1. .container .item:nth-child(5) {
  2. background-color: yellow;
  3. place-self: end end;
  4. place-self: end;
  5. }

间隙

  1. gap: 垂直方向 水平方向
  2. gap: 5px;

  1. gap: 5px 10px;

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