<div class="supports"></div>

<ul class="grid">
			<li class="title">
				<h2>
					Some Balloons
				</h2>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq5.jpg" alt="balloons">
          The Pattersons Balloon
          
				</div>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq1.jpg" alt="balloons">
          The Hardy's wine balloon, launching alongside a nice checked one.
				</div>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq3.jpg" alt="balloons">
          Virgin looking a bit skew.
				</div>
			</li>
			<li class="title">
				<h2>
					More balloons
				</h2>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq12.jpg" alt="balloons">
          The Swatch balloon
				</div>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq11.jpg" alt="balloons">
          Fortnum and Mason. What we know about this one is that it uses the correct Pantone colour.
				</div>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq10.jpg" alt="balloons">
          This one is quite snazzy.
				</div>
			</li>
			<li class="title">
				<h2>
					What do you know? Balloons!
				</h2>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq9.jpg" alt="balloons">
          Top of a balloon
				</div>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq8.jpg" alt="balloons">
          Lots of balloons
				</div>
			</li>
			<li>
				<div>
					<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/12005/balloon-sq7.jpg" alt="balloons">
          Wahey!
				</div>
			</li>

		</ul>
.grid {
  overflow: hidden;
  padding: 0.5em 0 0 0.5em;
  max-width: 56em;
  margin: 0 auto 20px auto;
  list-style: none;
}

.grid li {
  padding: 0 0.5em 0.5em 0;
}

.grid li img {
  display: block;
}

.grid h2 {
  font-size: 100%;
}

.grid li > div,
.grid li > h2 {
  background: #808080;
  color: #fff;
  text-align: center;
  margin: 0;
}

.grid li.title h2 {
  padding: 1em;
  width: 100%;
}

.grid li a {
  color: #fff;
}

@media all and (min-width: 500px) {
  .grid li {
    float: left;
    width: 33.3333333%;
  }
  .grid li.title {
    width: 100%;
  }
}

@media all and (min-width: 60em) {
  .grid li {
    width: 25%;
  }
  .grid li.title {
    width: 25%;
    clear: left;
  }
  .grid li.title h2 {
    padding: 7em 2em;
  }
}


/* for flexbox */

@supports(display: flex) {
  @media all and (min-width: 500px) {
    .grid {
      display: flex;
      flex-wrap: wrap;
    }
    .grid li {
      display: flex;
      flex-direction: column;
    }
    /* the original pattern and therefore our fallback styles uses padding on the li and then puts the background color on the inner element. We can't therefor make it stretch just by way of the default alignment of the flex item. By setting the li to a flex column we can then make the inner grow to the height of the external container.  */
    .grid li > * {
      flex: 1;
    }
  }
}


/* for grid */

@supports(display: grid) {

 
  @media all and (min-width: 500px) {
    .grid {
      display: grid;
    grid-gap: 15px;
    padding-right: 10px;
      grid-template-columns: repeat(3, 1fr);
    }
    .grid li {
      padding: 0;
    display: block;
    background: #808080;
      float: none;
      width: auto;
    }
    .grid li.title {
      width: auto;
      grid-column: 1 / 4;
    }
  }
  @media all and (min-width: 60em) {
    .grid {
      grid-template-columns: repeat(4, 1fr);
    }
    .grid li {
      width: auto;
    }
    .grid li.title {
      grid-column: 1 / 2;
    }
  }
}
Run Pen

External CSS

  1. https://codepen.io/rachelandrew/pen/c05f966e1a29d9120c06f0bae61f9cd9

External JavaScript

This Pen doesn't use any external JavaScript resources.