我有一些div
连续的网格系统。当屏幕太小而无法显示时,它们应该在一个新行中断开。我怎样才能做到这一点?
.parent {
width: 100%;
height: 800px;
display: grid;
grid-auto-flow: column;
background-color: blue;
grid-column-gap: 10px;
}
.item {
width: 200px;
height: 30px;
background-color: green;
border: 1px solid yellow;
}

<div class="parent">
<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 class="item"></div>
</div>
&#13;
更新 它应该根据屏幕大小而中断。因此,当屏幕宽度仅为250px时,单个块应该连续。
答案 0 :(得分:2)
试试这个
.parent {
width: 100%;
height: 800px;
background-color: blue;
}
.item {
width: 200px;
height: 30px;
background-color: green;
border: 1px solid yellow;
float: left;
}
<div class="parent">
<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 class="item"></div>
</div>
答案 1 :(得分:1)
试试这个:
.parent {
width: 100%;
height: 800px;
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: auto auto;
grid-gap: 10px;
background-color: blue;
padding: 10px;
}