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

              
                <div class="background">
  <div class="container" data-container>
    <div class="card" data-card style="background-image: url('https://source.unsplash.com/random/1')">1</div>
    <div class="card" style="background-image: url('https://source.unsplash.com/random/2')">2</div>
    <div class="card" style="background-image: url('https://source.unsplash.com/random/3')">3</div>
    <div class="card" style="background-image: url('https://source.unsplash.com/random/4')">4</div>
    <div class="card" style="background-image: url('https://source.unsplash.com/random/5')">5</div>
    <div class="card" style="background-image: url('https://source.unsplash.com/random/6')">6</div>
  </div>
  <div class="buttons">
    <button data-remove>–</button>
    <button data-add>+</button>
  </div>
</div>
              
            
!

CSS

              
                .container {
  background: #FF678C;
  box-sizing: border-box;
  display: flex;
  flex-flow: column wrap;
  height: 80vh;
  margin-bottom: 5vh;
  text-align: center;
  text-transform: uppercase;
  width: 90vw;
}

.card {
  align-items: center;
  background: white;
  background-size: cover;
  border: 5px solid white;
  box-sizing: border-box;
  color: white;
  display: flex;
  flex-grow: 0;
  font-family: sans-serif;
  font-size: 30px;
  font-weight: bold;
  height: 50%;
  justify-content: center;
  outline: 5px solid white;
  text-shadow: 0 0 5px black;
  
  // Setting the heights of the elements so they meet
  // nicely at the bottom of the container
  &:nth-child(6n - 5) {
    height: 25%;
  }
  
  &:nth-child(6n-4) {
    height: 75%;
  }
  
  &:nth-child(6n-3) {
    height: 50%;
  }
  
  &:nth-child(6n-2) {
    height: 50%;
  }
  
  &:nth-child(6n-1) {
    height: 66.666%;
  }
  
  &:nth-child(6n) {
    height: 33.333%;
  }
}

// Presentational Styles

body {
  margin: 0;
}

.background {
  align-items: center;
  background: #FF678C;
  display: flex;
  flex-direction: column;
  height: 100vh;
  justify-content: center;
  width: 100vw;
}

button {
  background: white;
  border: 2px solid transparent;
  border-radius: 0;
  color: #FF648A;
  cursor: pointer;
  font-size: 24px;
  font-weight: bold;
  padding: 10px 20px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  
  &:hover {
    background-color: #FF648A;
    border: 2px solid white;
    color: white;
  }
}

              
            
!

JS

              
                // This JS is not needed for the layout to work.
// All it does it add/remove images.

const add = document.querySelector('[data-add]');
const remove = document.querySelector('[data-remove]');
const card = document.querySelector('[data-card]');
const container = document.querySelector('[data-container]');
let number = 7;

add.addEventListener('click', () => {
  const addCard = card.cloneNode(true);
  const image = `url('https://source.unsplash.com/random/${Math.floor(Math.random() * 100)}')`;
  addCard.style.backgroundImage = image;
  addCard.innerHTML = number;
  container.appendChild(addCard);
  number++;
});

remove.addEventListener('click', () => {
  if (container.childElementCount > 0) {
    container.removeChild(container.lastElementChild);
  }
  
  if (number > 1) {
    number--;
  }
});
              
            
!
999px

Console