【发布时间】:2018-08-12 09:13:27
【问题描述】:
如何在下面的弹性项目中设置每行的最大项目数?我想用动画制作每行 4 个项目:
.grid-items {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.cell-item {
padding: 15px;
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-ms-transition: all 2s ease;
transition: all 2s ease;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
.cell-item a {
background-color: #f2f2f2;
width: 100%;
height: 200px;
display: block;
}
.cell-item:hover {
-webkit-box-flex: 4;
-ms-flex-positive: 4;
flex-grow: 4;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
transition: all 1s ease;
}
<div class="grid-items">
<div class="cell-item">
<a href="#">
</a>
</div>
<div class="cell-item">
<a href="#">
</a>
</div>
<div class="cell-item">
<a href="#">
</a>
</div>
<div class="cell-item">
<a href="#">
</a>
</div>
<div class="cell-item">
<a href="#">
</a>
</div>
<div class="cell-item">
<a href="#">
</a>
</div>
<div class="cell-item">
<a href="#">
</a>
</div>
<div class="cell-item">
<a href="#">
</a>
</div>
</div>
如果我向 flex 项目添加 25%,动画将不起作用:
.cell-item {
padding: 15px;
-webkit-transition: all 2s ease;
-moz-transition: all 2s ease;
-ms-transition: all 2s ease;
transition: all 2s ease;
-webkit-box-flex: 1 25%;
-ms-flex: 1 25%;
flex: 1 25%;
}
有什么想法吗?
【问题讨论】:
-
你的意思是你想做这样的事情jsfiddle.net/Lwbmpvcb/2
-
@Liamm12 是,但不要手动将它们分成两组。
标签: html css flexbox css-transitions