flex布局自适应换行
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.container {
display: flex;
flex-wrap: wrap;
gap:20px;
}
.item {
flex-grow: 1;
height: 50px;
flex-basis: 200px; /** 基础宽度,也就是最小宽度,,,例如这里是200px,,gap是20px也就是两个元素如果想要在一行显示最少需要200px+20px+200px 才能满足两个元素在一行显示的宽度 */
background-color: #ccc;
}
.item:nth-child(2n) {
background-color: #eee;
}
</style>
</head>
<body>
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</body>
</html>