Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1 style="text-align: center;">Masonry Grid Layout</h1>
<section class="grid-container">
  <div class="cols grid-area">
    <figure class="col grid-1">
      <img src="https://placeimg.com/640/640/animals" alt="">
      <figcaption>
        <h2>Title</h2>
        <div class="grid-button-wrapper">
          <button class="rww_grid_button">More Info</button>
        </div>
        <p>Filler sentance goes here.</p>
        <a href="#">View More</a>
      </figcaption>
    </figure>
    <div class="col grid-2">
      <img src="https://placeimg.com/640/640/any" alt="">
    </div>
    <figure class="col grid-3">
      <img src="https://placeimg.com/640/640/arch" alt="">
      <figcaption>
        <h2>Title</h2>
        <div class="grid-button-wrapper">
          <button class="rww_grid_button">More Info</button>
        </div>
        <p>Filler sentance goes here. It's longer to demonstrate how the text wrapping works.</p>
        <a href="#">View More</a>
      </figcaption>
    </figure>
    <div class="col grid-4">
      <img src="https://placeimg.com/640/640/nature" alt="">
    </div>
    <div class="col grid-5">
      <span class="text-container">
          <p>Focus statement</p>
        </span>
      <img src="https://placeimg.com/640/640/tech" alt="">
    </div>
    <div class="col grid-6">
      <img src="https://placeimg.com/640/640/grayscale" alt="">
    </div>
    <div class="col grid-7">
      <img src="https://placeimg.com/640/640/sepia" alt="">
    </div>
    <div class="col grid-8">
      <img src="https://placeimg.com/640/640/any" alt="">
    </div>
  </div>
</section>
              
            
!

CSS

              
                .grid-container {
  max-width: 1280px;
  margin: 0 auto;
}

.cols {
  margin: 0 auto;
  max-width: 1000px;
}

.col {
  width: 25%;
  height: 250px;
  float: left;
  margin: 0;
}

.col img {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0.8;
}

.col h2 {
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}

.grid-1 {
  width: 50%;
}

.grid-3 {
  float: right;
  height: 500px;
}

.grid-5 {
  display: table;
}

.grid-5 > * {
  display: table-cell;
}

.grid-5 > .text-container {
  text-align: center;
  vertical-align: middle;
  width: 50%;
}

.grid-5 img {
  object-position: right;
}

.grid-7 {
  width: 50%;
}

@supports (display: grid) or (display: -ms-grid) {
  .grid-area {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    grid-auto-rows: 250px;
    justify-content: center;
  }
  .col {
    width: 100%;
    height: 100%;
    float: none;
  }
  .grid-1 {
    grid-column-end: span 2;
  }
  .grid-3 {
    grid-row-end: span 2;
  }
  .grid-5 {
    grid-column-end: span 2;
  }
  .grid-7 {
    grid-column-end: span 2;
  }
}

/* Media queries for other screen widths */
@media screen and (max-width: 450px) {
  .col {
    grid-row-end: unset;
    grid-column-end: unset;
    height: 250px;
  }
  .grid-area {
    display: flex;
    flex-direction: column;
  }
  .grid-3 {
    order: -1;
    height: 500px;
  }
}

@media screen and (max-width: 768px) {
  .grid-2 {
    display: none;
  }
}

/************ Hover effect styles *************/

figure {
  position: relative;
  overflow: hidden;
  text-align: center;
  cursor: pointer;
}

figure figcaption {
  color: #fff;
  backface-visibility: hidden;
}

figure figcaption::before,
figure figcaption::after {
  pointer-events: none;
}

figure figcaption,
figure figcaption > a {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Anchor will cover the whole item by default */

/* For some effects it will show as a button */

figure figcaption > a {
  z-index: 1000;
  text-indent: 200%;
  white-space: nowrap;
  font-size: 0;
  opacity: 0;
}

figure h2 {
  word-spacing: -0.15em;
  font-weight: 300;
}

figure h2 span {
  font-weight: 800;
}

figure h2,
figure p {
  margin: 0;
}

figure button.rww_grid_button {
  background-color: transparent;
  border: 2px solid #fff;
  border-radius: 5px;
  margin: 0 auto;
  padding: 0.5rem;
  font-weight: bold;
  font-size: smaller;
  color: #fff;
  text-transform: uppercase;
  transition: all 0.3s;
}

figure p {
  letter-spacing: 1px;
  font-size: smaller;
}

figure figcaption::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    to bottom,
    rgba(72, 76, 97, 0) 0%,
    rgba(72, 76, 97, 0.8) 75%
  );
  content: "";
  opacity: 0;
  transform: translate3d(0, 50%, 0);
}

figure h2 {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  color: #484c61;
  transition: all 0.35s;
  transform: translate3d(0, -50%, 0);
}

figure figcaption::before,
figure p,
figure .grid-button-wrapper {
  transition: all 0.35s;
}

figure .grid-button-wrapper {
  position: absolute;
  bottom: 35%;
  left: 0;
  right: 0;
  width: 100%;
  opacity: 0;
  transform: translate3d(0, 20px, 0);
}

figure p {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  padding-bottom: 3rem;
  width: 100%;
  opacity: 0;
  transform: translate3d(0, 10px, 0);
}

figure:hover h2 {
  background: none;
  color: #fff;
  transform: translate3d(0, -50%, 0) translate3d(0, -40px, 0);
}

figure:hover figcaption::before,
figure:hover p,
figure:hover .grid-button-wrapper {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

              
            
!

JS

              
                
              
            
!
999px

Console