htmlcssflexbox

Controlling the amount of space in justify-content: space-between


I was wondering how to justify how much space is allowed in justify-content: space-between for flexbox.

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.

The snippet below will hopefully clarify what I'm struggling with.

Let me know if you need me to clarify further. Thanks!

#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>


Solution

  • The justify-content property uses the available space on the line to position flex items.

    With justify-content: space-between, all available space is placed between the first and last items, pushing both items to opposite edges of the container.

    You wrote:

    I was wondering how to justify how much space is allowed in justify-content: space-between for flexbox.

    With space-between in row-direction, you would have to control the width of the flex container. So if you want there to be less space between flex items, then you would need to shorten the width of the container.

    Or you could use justify-content: space-around.

    However, these solutions are suboptimal.

    The right way to go about this would be to use margins.

    You wrote:

    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.

    Use justify-content: center then use margins to space them apart.