* { margin: 0; padding: 0; background-color: #F0F8FF; } #layout { display: flex; /* 主轴方向为纵向 */ flex-direction: column; width: 80%; /* 居中 */ margin: 0 auto; } #top { width: 100%; /* 这里的100%相当于父级 layout 的80%*/ flex: 0 0 50px; margin: 0 auto; background-color: yellow; /* height: 50px; */ } #main { flex: 0 0 100%; display: flex; flex-direction: row; /* 默认,可设可不设 */ } #main div:first-child { flex: 0 0 10%; background-color: #F0F8FF; list-style-type: none; display: flex; /* 设置允许换行 */ flex-wrap: wrap; border-left: 1px solid white; border-right: 1px solid white; } #main div:first-child li { flex: 0 0 100%; height: 40px; /* 设置文字水平居中 */ line-height: 40px; text-align: center; border-bottom: 1px solid white; } #main div:nth-child(2) { flex: 0 0 90%; background-color: #F0F8FF; list-style-type: none; display: flex; /* 设置允许换行 */ flex-wrap: wrap; /* 设置间隔 */ justify-content: space-around; } #main div:nth-child(2) li { flex: 0 0 30%; height: 120px; text-align: center; border-bottom: 1px solid white; background-color: greenyellow; margin-top: 10px; }