Blogger Information
Blog 12
fans 0
comment 0
visits 5782
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1027作业
PHP是世界上最好的语言
Original
462 people have browsed it

作业内容:实例演示隐式网格, 对齐方式与行列间隙的设置方式与使用场景、前提

隐式网格

html

  1. <div class="container">
  2. <div class="item">item1</div>
  3. <div class="item">item2</div>
  4. <div class="item">item3</div>
  5. <div class="item">item4</div>
  6. <div class="item">item5</div>
  7. <div class="item">item6</div>
  8. <div class="item">item7</div>
  9. <div class="item">item8</div>
  10. <div class="item">item9</div>
  11. <div class="item other">item10</div>
  12. <div class="item other">item11</div>
  13. </div>

css

  1. .container {
  2. width: 400px;
  3. display: grid;
  4. /* 显式网格 */
  5. grid-template-columns: repeat(3, 1fr);
  6. grid-template-rows: repeat(3, 50px);
  7. /* 1. 排列规则 */
  8. grid-auto-flow: row;
  9. /* 2. 隐式网格 */
  10. /* 多余的项目,出现在隐式网格中(自动生成) */
  11. grid-auto-rows: 50px;
  12. }

效果

前提:项目比网格指定的要多。
使用场景:想要增加要展示的数据时。比如,以前的涉及是显示9张图片,而现在想要展示11张图片,可以使用隐式网格,不用修改原有的html。

对齐方式

htm

  1. <div class="container">
  2. <div class="item">item1</div>
  3. <div class="item">item2</div>
  4. <div class="item">item3</div>
  5. <div class="item">item4</div>
  6. <div class="item">item5</div>
  7. <div class="item">item6</div>
  8. <div class="item">item7</div>
  9. <div class="item">item8</div>
  10. <div class="item">item9</div>
  11. </div>

css
1.项目在”容器”中的对齐
place-content

  1. /* 创建容器的剩余空间 */
  2. .container {
  3. /* 当前 300 * 300 */
  4. width: 450px;
  5. height: 450px;
  6. border: 1px solid #000;
  7. background-color: lightcyan;
  8. place-content: center;
  9. }

效果

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

  1. .container {
  2. /* 当前 300 * 300 */
  3. width: 450px;
  4. height: 450px;
  5. border: 1px solid #000;
  6. background-color: lightcyan;
  7. place-content: center;
  8. /*项目在"单元格"中的对齐 */
  9. place-items: center;
  10. }

效果

3.设置某个项目在单元格对齐方式
place-self

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

效果

前提: 必须存在”剩余空间”

使用场景:图片、网站某一栏目等的排列和布局

行列间隙

html

  1. <div class="container">
  2. <div class="item">item1</div>
  3. <div class="item">item2</div>
  4. <div class="item">item3</div>
  5. <div class="item">item4</div>
  6. <div class="item">item5</div>
  7. <div class="item">item6</div>
  8. <div class="item">item7</div>
  9. <div class="item">item8</div>
  10. <div class="item">item9</div>
  11. </div>

css

  1. .container {
  2. display: grid;
  3. grid-template-columns: repeat(3, 100px);
  4. grid-template-rows: repeat(3, 100px);
  5. /* 行列间隙 gap */
  6. /* gap: 垂直方向 水平方向 */
  7. gap: 10px;
  8. }
  9. .container > .item {
  10. background-color: wheat;
  11. }

效果

使用场景:统一调整项目之间的边距的时候

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