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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <header>
  <nav>
    <a href="#">Super App 3000</a>
    <ul class="menu">
      <li>Choose Grid Layout:</li>
      <li>
        <button class="is-current js-layout-button" type="button" data-layout-toggle="1">
          Three columns
        </button>
      </li>
      <li>
        <button class="js-layout-button" type="button" data-layout-toggle="2">
          Two columns
        </button>
      </li>
      <li>
        <button class="js-layout-button" type="button" data-layout-toggle="3">
          One column
        </button>
      </li>
    </ul>
  </nav>
</header>

<main class="grid js-grid" data-layout="1">
  <div id="module_1"><span>1</span></div>
  <div id="module_2"><span>2</span></div>
  <div id="module_3"><span>3</span></div>
</main>

<footer>
  <p>
    &copy; #currentyear &ndash;
    <a href="https://www.bshow.co/">Bobby Showalter</a>
  </p>
</footer>
              
            
!

CSS

              
                /**
 * Grid Layout magic!
 */
@media screen and (min-width: 60rem) {
  /* parent grid settings */
  .grid {
    display: grid;
    align-items: start;
    grid-column-gap: 1rem;
  }
  
  /* layout 1 styles */
  .grid[data-layout="1"] {
    grid-template: min-content / 15rem 1fr 15rem;
  }
  
  /* layout 2 styles */
  .grid[data-layout="2"] {
    grid-template: repeat(2, min-content) / 1fr 15rem;
  }
  
  .grid[data-layout="2"] #module_1 {
    grid-area: 1 / 1 / 2 / 2;
  }
  
  .grid[data-layout="2"] #module_2 {
    grid-area: 2 / 1 / 3 / 2;
  }
  
  .grid[data-layout="2"] #module_3 {
    grid-area: 1 / 2 / 3 / 3;
  }
  
  /* layout 3 styles */
  .grid[data-layout="3"] {
    grid-template: repeat(3, min-content) / 100%;
  }
}



/**
 * Beautification stuff
 */

/* |Variables */
:root {
  /* colors */
  --c-white: #fbfbfb;
  --c-light-gray: #dfe6e9;
  --c-gray: #b2bec3;
  --c-shadow: #636e7255; /* #rrggbbaa */
  --c-text: #2d3436;
  --c-red: #d6303155;
  --c-green: #00b89455;
  --c-blue: #0984e355;
}

/* |Styles */
html {
  background-color: var(--c-light-gray);
  box-sizing: border-box;
  color: var(--c-text);
  font-family: 'Work Sans', sans-serif;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

html,
body {
  height: 100%;
}

body {
  display: grid;
  grid-template-rows: min-content 1fr min-content;
}

header,
footer {
  background-color: var(--c-gray);
  border: 2px solid var(--c-shadow);
}

footer p {
  margin: 0;
  padding: 1rem;
}

footer p a {
  color: var(--c-text);
  font-weight: 700;
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
}

nav a {
  color: var(--c-text);
  font-size: 1.5rem;
  font-weight: 700;
}

.menu {
  display: flex;
  align-items: center;
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.menu li + li {
  margin-left: 1rem;
}

.menu button {
  background: transparent;
  border: 1px solid var(--c-text);
  border-radius: 3px;
  color: var(--c-text);
  font-family: inherit;
  padding: .25rem .75rem;
  transition:
    background-color 250ms ease-out,
    color 250ms ease-out;
}

.menu button:hover {
  background-color: var(--c-light-gray);
}

.menu button.is-current {
  background-color: var(--c-text);
  color: var(--c-light-gray);
}

main {
  margin: 2.25rem 0;
  padding: 0 1rem;
}

.grid div {
  border-radius: 3px;
  box-shadow: 0 1px 3px var(--c-shadow);
  margin-bottom: 1rem;
  padding: 1rem;
}

.grid div span {
  display: block;
  font-size: calc(1vw + 1.5rem);
  font-weight: 900;
  padding: 1rem 1.5rem;
}

#module_1,
#module_1 span {
  background-color: var(--c-red);
  min-height: 200px;
}

#module_2,
#module_2 span {
  background-color: var(--c-green);
  min-height: 600px;
}

#module_3,
#module_3 span {
  background-color: var(--c-blue);
  min-height: 350px;
}
              
            
!

JS

              
                const layoutButtons = document.querySelectorAll('.js-layout-button');
const mainGrid = document.querySelector('.js-grid');

function changeLayout(e) {
  e.preventDefault();
  layoutButtons.forEach(button => {
    button.classList.remove('is-current');
  });
  let layoutChoice = this.getAttribute('data-layout-toggle');
  mainGrid.setAttribute('data-layout', layoutChoice);
  this.classList.add('is-current');
}

layoutButtons.forEach(button => button.addEventListener('click', changeLayout));
              
            
!
999px

Console