CSS grid-auto-flow 属性值说明

描述
row通过填充每一行来放置项目(item)(item),如有必要,添加新行。这是此属性的默认值。
column通过填充每列来放置项目(item)(item),如有必要,添加新列。
dense如果较小的物品稍后提出,请将物品填充网格中的任何孔。
row-dense通过填充每一行,并填充网格中的孔。
column-dense通过填充每列来填充物品,并填充网格中的孔。
initial使属性使用其默认值。
inherit从父母元素继承属性。
CSS grid-auto-flow 属性

grid-auto-flow 属性控制自动放置的项目(item)(item)如何流入网格。

此属性具有以下值:行、列、密集、行密集、列密集。
如果既没有提供“行”也没有提供“列”值,则假定为“行”。

grid-auto-flow 属性可以有一个关键字(密集、列或者行)或者两个关键字(列密集或者行密集)。

初始值row
应用于网格容器。
继承无效
可动画的是的。
版本CSS网格布局模块级别1
DOM 语法object.style.gridautoflow =“row”;

语法

grid-auto-flow: row | column | dense | row dense | column dense | initial | inherit;

grid-auto-flow 属性示例:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grey-container {
        display: grid;
        grid-template-columns: auto auto auto;
        grid-template-rows: auto auto;
        grid-auto-flow: column;
        grid-gap: 10px;
        background-color: #ccc;
        padding: 10px;
      }
      .grey-container > div {
        background-color: #eee;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-auto-flow 属性示例</h2>
    <h3>grid-auto-flow: column</h3>
    <div class="grey-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
    </div>
  </body>
</html>

其中通过填充每一列来放置项目(item)(item)。
在下面的示例中,我们可以看到通过填充每一行来放置项目(item)(item)。

此属性的效果取决于指定的值。
z>0 的 3D 元素变大,z<0 的 3D 元素变小。
数值越小,视觉效果越令人印象深刻。

带有 grid-template-columns 属性的 grid-auto-flow 属性示例:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .white-container {
        display: grid;
        grid-template-columns: auto auto auto;
        grid-template-rows: auto auto;
        grid-auto-flow: row;
        grid-gap: 10px;
        background-color: #ccc;
        padding: 10px;
      }
      .white-container > div {
        background-color: #fff;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-auto-flow 属性示例</h2>
    <h3>grid-auto-flow: row</h3>
    <div class="white-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
    </div>
  </body>
</html>

具有“row”值的 grid-auto-flow 属性示例:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grey-container {
        height: 250px;
        width: 250px;
        display: grid;
        grid-gap: 20px;
        grid-template: repeat(4, 1fr)/repeat(2, 1fr);
        grid-auto-flow: row;
        background-color: #ccc;
        padding: 10px;
      }
      .box1 {
        background-color: #00f3ff;
        grid-row-start: 3;
      }
      .box2 {
        background-color: #ff00d4;
      }
      .box3 {
        background-color: #827c7c;
      }
      .box4 {
        grid-column-start: 2;
        background-color: orange;
      }
    </style>
  </head>
  <body>
    <div class="grey-container">
      <div class="box1"></div>
      <div class="box2"></div>
      <div class="box3"></div>
      <div class="box4"></div>
    </div>
  </body>
</html>

具有“列”值的 grid-auto-flow 属性示例:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grey-container {
        height: 250px;
        width: 250px;
        display: grid;
        grid-gap: 20px;
        grid-template: repeat(4, 1fr)/repeat(2, 1fr);
        grid-auto-flow: column;
        background-color: #ccc;
        padding: 10px;
      }
      .box1 {
        background-color: #00f3ff;
        grid-row-start: 3;
      }
      .box2 {
        background-color: #827c7c;
      }
      .box3 {
        background-color: #ff00d4;
      }
      .box4 {
        grid-column-start: 2;
        background-color: #4cbb13;
      }
    </style>
  </head>
  <body>
    <div class="grey-container">
      <div class="box1"></div>
      <div class="box2"></div>
      <div class="box3"></div>
      <div class="box4"></div>
    </div>
  </body>
</html>

具有“列密集”值的 grid-auto-flow 属性示例:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grey-container {
        height: 250px;
        width: 250px;
        display: grid;
        grid-gap: 20px;
        grid-template: repeat(4, 1fr)/repeat(2, 1fr);
        grid-auto-flow: column dense;
        background-color: #ccc;
        padding: 10px;
      }
      .box1 {
        background-color: #0ad6e0;
        grid-row-start: 3;
      }
      .box2 {
        background-color: #841c72;
      }
      .box3 {
        background-color: #827c7c;
      }
      .box4 {
        grid-column-start: 2;
        background-color: #4cbb13;
      }
    </style>
  </head>
  <body>
    <div class="grey-container">
      <div class="box1"></div>
      <div class="box2"></div>
      <div class="box3"></div>
      <div class="box4"></div>
    </div>
  </body>
</html>

具有“row-dense”值的 grid-auto-flow 属性示例:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grey-container {
        height: 250px;
        width: 250px;
        display: grid;
        grid-gap: 20px;
        grid-template: repeat(4, 1fr)/repeat(2, 1fr);
        grid-auto-flow: row dense;
        background-color: #ccc;
        padding: 10px;
      }
      .box1 {
        background-color: #0ad6e0;
        grid-row-start: 3;
      }
      .box2 {
        background-color: #841c72;
      }
      .box3 {
        background-color: #827c7c;
      }
      .box4 {
        grid-column-start: 2;
        background-color: #4cbb13;
      }
    </style>
  </head>
  <body>
    <div class="grey-container">
      <div class="box1"></div>
      <div class="box2"></div>
      <div class="box3"></div>
      <div class="box4"></div>
    </div>
  </body>
</html>
日期:2020-06-02 22:14:33 来源:oir作者:oir