Flexbox - Horizontal component with full height squared image

Viewed 1115

I try to achieve what seems to be a very easy task with flexbox, but after hours, I fail...

I just want to create a responsive horizontal component with an image on the left who always be 100% height and some flexible width text on the right.

Should be easy, but the image never stops overlapping in the best case...

body {
  font-family: sans-serif;
}

.card {
  background: #F1F1F2;
  display: flex;
}

.card-img {
  border: 1px solid green;
}

img {
  display: block;
  height: 100%;
  width: auto;
}

.card-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid blue;
}
<div class="card">
  <div class="card-img">
    <img src="http://placehold.it/100x100" alt="Card image">
  </div>
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">Some amazing content lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
  </div>
</div>

4 Answers
Related