<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>div上下左右排序</title>
</head>
<style>
.div-box {
display: grid;
grid-auto-flow: column; /* 排序方式: column-先列后行, row-先行后列 */
grid-template-columns: repeat(4, 207px); /* 设计列宽 */
grid-template-rows: repeat(2,138px); /* 设计行高 */
/* grid-template-rows: repeat(2,auto); */
grid-row-gap: 24px; /* 行间距 */
grid-column-gap: 177px; /* 列间距 */
}
.div-box2 {
display: grid;
grid-auto-flow: row;
grid-template-columns: repeat(4, 207px);
grid-template-rows: repeat(2,138px);
/* grid-template-rows: repeat(2,auto); */
grid-row-gap: 24px;
grid-column-gap: 177px;
}
.div-item {
background-color: #0ec885;
line-height: 138px;
text-align: center;
}
</style>
<body>
<h2>排列:先列后行</h2>
<div class="div-box">
<div class="div-item">1</div>
<div class="div-item">2</div>
<div class="div-item">3</div>
<div class="div-item">4</div>
<div class="div-item">5</div>
<div class="div-item">6</div>
</div>
<h2>排列:先行后列</h2>
<div class="div-box2">
<div class="div-item">1</div>
<div class="div-item">2</div>
<div class="div-item">3</div>
<div class="div-item">4</div>
<div class="div-item">5</div>
<div class="div-item">6</div>
<div class="div-item">7</div>
<div class="div-item">8</div>
</div>
</body>
</html>