重要的是justify-content: center;align-items: center;
父元素设置flex-wrap: wrap;换行,设置宽高。

<!DOCTYPE html>
<html>
<style>
.box{
display:flex;
width: 300px;
height: 300px;
border: 1px solid #f00;
flex-wrap: wrap;
justify-content: center;
align-items: center;
margin-top: 100px;
margin-left: 100px;
}
.item{
display: flex;
/*flex-direction: column;*/
width: 80px;
height: 80px;
background-color: #890;
border: 1px solid #000000;
justify-content: center;
align-items: center;
}
</style>
<body>
<div class="box">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
<div class="item">9</div>
</div>
</body>
</html>
12-27 09:56