改变顺序方向,默认是顺序row
grid-auto-flow: row;
grid-auto-flow: column;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>间距</title>
<style>
.box{
width: 600px;
height: 600px;
border: 5px solid gray;
display: grid;
grid-template-rows: repeat(3,100px);
grid-template-columns: repeat(3,100px);
/* 改变顺序方向,默认是顺序row grid-auto-flow: row; */
grid-auto-flow: column;
}
.box div{
border: 1px solid green;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
</body>
</html>
设置成column 就变成竖着的
grid-auto-flow: column;
控制九宫格方位
类似弹性盒属性自己搭配
justify-content: center;
align-content: space-around;
控制大盒子中的九宫格里面的每一个项目的属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>间距</title>
<style>
.box{
width: 600px;
height: 600px;
border: 5px solid gray;
display: grid;
grid-template-rows: repeat(3,100px);
grid-template-columns: repeat(3,100px);
justify-content: center;
align-content: center;
justify-items: center;
align-items: center;
简写形式
place-content: center center;
place-items: center center;
/* 改变顺序方向,默认是顺序row grid-auto-flow: row; */
/* grid-auto-flow: column; */
}
.box div{
border: 1px solid green;
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<div class="box">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
</body>
</html>
设置九宫格在大盒子中居中,并且九宫格中每一个项目也居中
justify-content: center;
align-content: center;
justify-items: center;
align-items: center;
简写形式
place-content: center center;
place-items: center center;