我想知道如何证明 flexbox 的 justify-content: space-between
允许多少空间。
目前,我的元素是有间隔的,但它们之间的空间太大了,我只想在它们之间留一点空间,这样它们就可以连续放置在中间的某个地方。
下面的代码片段有望阐明我正在努力解决的问题。
如果您需要我进一步说明,请告诉我。谢谢!
#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>
最佳答案
justify-content
属性使用行上的可用空间来定位 flex 元素。
使用 justify-content: space-between
,所有可用空间都放在第一个和最后一个元素之间,将两个元素推到容器的相对边缘。
你写道:
I was wondering how to justify how much space is allowed in
justify-content: space-between
for flexbox.
在行方向上使用 space-between
时,您必须控制 flex 容器的宽度。因此,如果您希望 flex 元素之间的空间更小,则需要缩短容器的宽度。
或者您可以使用justify-content: space-around
。
但是,这些解决方案都不是最优的。
解决这个问题的正确方法是使用边距。
你写道:
Currently, my items are spaced but they have way too much space between them I want just a little space between them so they can settle somewhere in the middle in a row.
使用 justify-content: center
然后使用边距将它们分开。
关于html - 控制 justify-content : space-between 中的空间量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42080123/