Large space between LI when only two boxes shown - why?

I have been developing a small template, this is the entry from my CSS causing problems:

body {
  background-color: #D6ECEF;
  font-family: Helvetica, sans-serif;
}

header.commerce1 {
  background-color: #D2691E;
  color: #FFFF;
  border-radius: 5px;
  padding: 22px;
}

a {
  text-decoration: none;
}

div.content {
  background-color: #FFF;
  width: 860px;
}

body {
  font-family: sans-serif;
}

ul.stock {
  display: flex;
  flex: 1 0 20%;
  flex-grow: 3;
  flex-wrap: wrap;
  flex-basis: 100%;
  width: 800px;
  margin-left: 16px;
  margin-top: -40px;
  list-style: none;
  margin: 1px;
  justify-content: space-between;
}

ul.stock li {
  font-family: sans-serif;
  font-size: 88%;
  color: #333;
  background-color: #FFF;
  column-gap: 3px;
  border: 3px solid;
  margin-left: 40px;
  margin-bottom: 10px;
  max-height: auto;
  width: 250px;
  margin-right: 0px;
  margin: 0 0 20px 0;
  justify-content: flex-end;
}

ul.stock li h3 {
  font-size: 1.2em;
}


/* 

ul.dealers li h3 {
color: red;
}
*/

ul.stock li p {
  font-size: 0.75rem;
  width: 230px;
  white-space: initial;
  padding: 3px;
  margin-right: 20px;
}

ul.stock li img {
  height: 180px;
}

a {
  text-decoration: none;
}

hr {
  height: 1px;
  background-color: #a2a9b1;
  border: 0;
  margin: 0.2em 0
}

p {
  margin: 0.4em 0 0.5em 0
}

p img {
  margin: 0
}

ul {
  margin: 0.3em 0 0 1.6em;
  padding: 0
}

ol {
  margin: 0.3em 0 0 3.2em;
  padding: 0;
  list-style-image: none
}

li {
  margin-bottom: 0.1em
}

dt {
  font-weight: bold;
  margin-bottom: 0.1em
}

dl {
  margin-top: 0.2em;
  margin-bottom: 0.5em
}

dd {
  margin-left: 1.6em;
  margin-bottom: 0.1em
}

h3,
h4,
h5,
h6 {
  margin: 30px 0 0
}

h2,
h3,
h4,
h5,
h6 {
  padding: 0;
  position: relative
}


/* 
h2 {
font-size:18pt;
line-height:24pt;
margin-bottom:0.25em
}
h3 {
font-size:14pt;
line-height:20pt
}
h4,
h5,
h6 {
font-size:12pt;
line-height:16pt
}
*/

h2 {
  line-height: 24pt;
  margin-bottom: 0.25em;
}

h3 {
  line-height: 20pt;
}

h4,
h5,
h6 {
  line-height: 16pt;
}

ol,
ul {
  margin: 10px 0 0 1.6em;
  padding: 0
}

ol li,
ul li {
  padding: 2px 0;
  font-size: 12pt
}

q {
  quotes: '"' '"' "'" "'"
}

blockquote {
  overflow: hidden;
  margin: 1em 0;
  padding: 0 40px
}

h3 {
  margin-top: 10px;
}

hr.archive-aex {
  border: 5px dotted #ff0000;
  border-style: none none dotted;
  color: #fff;
  background-color: #fff;
}

#content {}

[id="Content"] {
  font-size: 14px;
}

.mw-body {
  padding: 1.25em 1.5em 1.5em 1.5em;
}

.mw-body {
  margin-top: -1px;
  border: 1px solid #a7d7f9;
  border-right-width: 0;
}

[id="bodyContent"] p,
.vector-body p {
  margin: 0.5em 0;
}

[id="bodyContent"],
.vector-body {
  font-size: calc(1em * 0.875);
  line-height: 1.6;
}

div.stockimg img {
  width: 250px;
}
<header class="commerce1">
  <h2>MY AUCTION SITE TEMPLATE</h2>
</header>
<div class="content">
  <h3>T-SHIRTS SALE</h3>
  <ul class="stock">
    <li>
      <div class="stockimg">
        <img src="https://upload.wikimedia.org/wikipedia/commons/e/e6/LIOR_FOR_ATHENA.JPG">
        <p><b>Women's T-shirt</b>, white <b>WAS £10.00 NOW £5.00</b>
    </li>
    <li>
      <div class="stockimg">
        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/11_p_edit_edit.jpg/800px-11_p_edit_edit.jpg">
      </div>
      <p><b>Men's blue T-shirt</b>, Size M <b>WAS £8.00 NOW £5.00</b>
    </li>
  </ul>
  </div>

Image from development site:

Image from site

If the ul class stock has three items in the list, the space isn't huge, but if there's only two it's huge.

I've been trying to experiment with margins and it's still got quite a large gap in between if there's two rows.

How could I fix the margin so that if there's just two items in a list it's not a huge gap, currently I've been trying to fix gap, columns etc.?


Solution 1:

This is due to your flex justification being space-between, which distributes an even amount of space between items. This is why two listings results in a larger gap than three.

Try using justify-content: flex-start on your ul and adding a the value you'd like to be your margin as a gap (for example, gap: 1rem).