JSFiddle - React, Tailwind, and code Playground

nested flexbox css wrapped image

by Andrew Pougher

HTML

<div class="product-out">
  <img src="http://placehold.it/1200/93ec46/ffffff/&text=andrew" alt="image description">
</div>
<hr>


<div class="products">
  <div class="product-outer">
    <div class="product-inner">
      <a href="/path/to/product/" class="featured-image">
        <div class="product-thumbnail">
          <img src="http://placehold.it/1200/23ec26/ffffff/&text=andrew" alt="image description">
        </div>
      </a>
      <h3 class="product-title text-center">
				<a href="/path/">TITLE</a>
			</h3>
      <div class="price-area text-center">
        <strike class="rrp"><span>£500</span></strike>
        <div class="price text-center">£300</div>
      </div>
      <button class="btn btn-block btn-default text-center">Add to cart</button>
      <a class="btn btn-xs  small text-muted" href="#">Find out more</a>
    </div>
  </div>
</div>

CSS

.product-out {
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: 100%;
  margin: 0;
  padding: 10px;
  background: #FFF;
  border: 1px solid #EEE;
}

.product-out img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: auto;
  /* THROTTLE THE HEIGHT OF POTENTIALLY HUGE IMAGES */
}

.products {
  display: flex;
  flex-flow: row wrap;
  /* ENSURES THAT THE GRID OVERSPILLS TO SUBSEQUENT ROWS */
}

.product-outer {
  display: flex;
  width: 33.33%;
  /* THREE PER ROW */
  margin-bottom: 20px;
  padding: 0 10px;
}

.product-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 10, 9, .15);
}

.featured-image {
  display: block;
}

.product-thumbnail {
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: 100%;
  margin: 0;
  padding: 10px;
  background: #FFF;
  border: 1px solid #EEE;
}

.product-thumbnail img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 180px;
}

.product-title {
  flex-grow: 1;
}