控制 justify-content: space-between 中的空间量

新手上路,请多包涵

我想知道如何证明在 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 许可协议

阅读 634
2 个回答

justify-content 属性使用行上的可用空间来定位弹性项目。

使用 justify-content: space-between ,所有可用空间都放置在第一个和最后一个项目之间,将两个项目推到容器的相对边缘。

你写了:

我想知道如何证明在 justify-content: space-between 中允许多少空间用于 flexbox。

使用 space-between 在行方向,您将必须控制 flex 容器的宽度。因此,如果您希望弹性项目之间的空间更小,则需要缩短容器的宽度。

或者您可以使用 justify-content: space-around

然而,这些解决方案都不是最优的。

解决这个问题的正确方法是使用边距。

你写了:

目前,我的物品是有间隔的,但它们之间的空间太大了,我只想在它们之间留一点空间,这样它们就可以连续地放在中间的某个地方。

使用 justify-content: center 然后使用边距将它们分开。

原文由 Michael Benjamin 发布,翻译遵循 CC BY-SA 3.0 许可协议

我的解决方案是:

  • 在指定最大高度的中间放置虚拟空 div
  • 将空格更改为 flex-start
  • 将内容块设置为 nogrow
  • 设置虚拟 div 增长

然后空间增长到指定的最大值。

原文由 Simon_Weaver 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题