1

I have made a simple flexbox jsfiddle To play around with all flexbox values, but stumbled upon something that I can't explain my .item divs are spaced out for some reason and .grid is automatically stretching to full height, I'm not entirely sure why this happens?

HTML

<div class="container">
  <div class="grid">
    <div class="item red">a</div>
    <div class="item yellow">b</div>
    <div class="item blue">c</div>
  </div>
</div>

CSS

.container {
  width: 320px;
  height: 480px;
  background: black;
  padding:15px;
  margin: 20px auto;
  display: flex;
}

.grid {
  background: white;
  display: flex;
  width: 100%;
  justify-content: flex-start;
  align-items: flex-start;
  flex-direction: row;
  flex-wrap: wrap;
}

.item {
  width: 100%;
  flex-grow: 0;
  flex-basis: 100%;
  align-self: auto;
  align-items: flex-start;
  padding: 10px 0;
}

.red { background: red; }
.yellow { background: yellow; }
.blue { background: blue; }
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Ilja
  • 44,142
  • 92
  • 275
  • 498

1 Answers1

1

The align-items: flex-start (set on .grid) causes this type of behavior. As specified in the MDN docs

The CSS align-items property defines how the browser distributes space between and around flex items along the cross-axis of their container.

If you disable it, the value will be set to stretch by default (each flex item will be stretched to fill the container).

Ramiz Wachtler
  • 5,623
  • 2
  • 28
  • 33