// 固定数量和宽度
display: grid;
grid-template-columns: 90px 100px 110px;
grid-template-rows: 110px 100px 90px;
// 固定数量,宽度自适应
display: grid;
grid-template-columns: repeat(3, 33.33%);
grid-template-rows: repeat(3, 33.33%);
// 固定宽度,数量自适应
display: grid;
grid-template-columns: repeat(auto-fill, 100px);
auto-fit,内容将被拉伸以填满整个行的宽度。
auto-fill,浏览器将允许空列像它们的非空邻居一样占据行中的空间–即使它们中没有网格项,也会被分配一部分空间
display: grid;
grid-template-columns: repeat(auto-fill, minmax(120px, auto));
grid-template-columns: repeat(auto-fit, minmax(120px, auto)); // 各网格宽度自动分配
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); // 各网格宽度平均分配
grid-template-columns: repeat(auto-fit, minmax(120px, 0.25fr)); // 各网格宽度平均分配(最大1/4)
grid-gap: 9px 30px;
// 设置间距
grid-row-gap: 20px;
grid-column-gap: 20px;
// 也可以使用 justify-content 属性和 align-content 属性
justify-items 属性,
align-items 属性,设置单元格对齐方式
place-items 属性是align-items属性和justify-items属性的合并简写形式。
顺序由grid-auto-flow属性决定,默认值是row,即"先行后列"。也可以将它设成column,变成"先列后行"。
// grid-template-areas 配合 grid-area 一起使用
// 指定网格定义区域
grid-template-areas: 'a b c'
'e f g'
'h i j';
// 多个单元格合并成一个区域的写法如下。
// 如果某些区域不需要利用,则使用"点"(.)表示。
grid-template-areas: 'a a b'
'c . b'
'c d d';
// 指定网格所在区域
grid-area:a;