我想知道如何证明在 justify-content: space-between
中允许多少空间用于 flexbox。
目前,我的物品是有间隔的,但它们之间的空间太大了,我只想在它们之间留一点空间,这样它们就可以连续地放在中间的某个地方。
下面的代码片段有望澄清我正在努力解决的问题。
如果您需要我进一步澄清,请告诉我。谢谢!
#qwrapper {
display: flex;
height: 100%;
width: 100%;
align-items: center;
justify-content: center;
}
.row {
flex: 0 auto;
height: 100px;
margin: 0;
}
#lighticon {
padding-bottom: 30px;
}
@media (max-width: 800px) {
#qwrapper {
flex-direction: column;
align-items: center;
}
}
@media screen and (max-width: 480px) {
#qwrapper {
flex-wrap: wrap;
}
.row {}
}
@media only screen and (min-width: 760px) {
#qwrapper {
justify-content: space-between;
margin: 10px;
}
#lighticon {
position: relative;
margin-left: 100px;
}
}
<div id="qwrapper">
<h3 id="michelle" class="row">"She always thinks of her clients."
<br>
</h3>
<img src="https://cdn4.iconfinder.com/data/icons/black-icon-social-media/512/099310-feedburner-logo.png" class="row" alt="" id="lighticon" />
<h3 id="jerry" class="row">"Very smart, creative person, problem solver."
<br>
</h3>
</div>
原文由 Cakers 发布,翻译遵循 CC BY-SA 4.0 许可协议
justify-content
属性使用行上的可用空间来定位弹性项目。使用
justify-content: space-between
,所有可用空间都放置在第一个和最后一个项目之间,将两个项目推到容器的相对边缘。你写了:
使用
space-between
在行方向,您将必须控制 flex 容器的宽度。因此,如果您希望弹性项目之间的空间更小,则需要缩短容器的宽度。或者您可以使用
justify-content: space-around
。然而,这些解决方案都不是最优的。
解决这个问题的正确方法是使用边距。
你写了:
使用
justify-content: center
然后使用边距将它们分开。