.Cards {
justify-content: center;
display: flex;
align-items: center;
text-align: center;
align-items: center;
flex-direction: row;
flex-wrap: wrap;
.Card {
text-align: center;
padding: 20px;
flex: 1 0 50%; // !
}
}我正在尝试让这个flexbox设置每行最多2个子对象。即使使用flex: 1 0 50%,我也得到了这样的结果:


为什么会发生这种情况?即使添加width: 50px也不起作用。
发布于 2021-07-06 03:34:30
css中的一个技巧:
width: calc(100%/2);将此放入卡中
.Cards{
...
.Card{
width: calc(100%/2);
...
}
}有关计算的更多信息:https://developer.mozilla.org/en-US/docs/Web/CSS/calc()
新的方法,这也很容易阅读。
https://stackoverflow.com/questions/68261012
复制相似问题