0

I have a series of div aligned in a row with flexbox. Their heights differ and the largest one sets a common height for all the div. An example is given in this JSFiddle:

enter image description here

HTML:

<div>
  <div class="big">
    hello
  </div>
  <div>
    bonjour
  </div>
</div>

CSS:

div {
  display: flex;
  flex-direction: row;
  border-color: gray;
  border-style: solid;
  border-width: 5px;
}

.big {
  height: 100px;
}

The box with "hello" is set to 100px and the natural height of the one with "bonjour" is much smaller. It however inherits the height of its bigger neighbour.

How can I have heights driven by the contents rather than by the maximum size of divs within a series of boxes aligned next to each others?

WoJ
  • 27,165
  • 48
  • 180
  • 345

1 Answers1

2

Just use align-items: flex-start; to parent div.

div {
  display: flex;
  flex-direction: row;
  border-color: gray;
  border-style: solid;
  border-width: 5px;
  align-items: flex-start; // Here
}

Working Fiddle

ketan
  • 19,129
  • 42
  • 60
  • 98