Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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="Demo-controls">
  <button name="prev">Previous step</button>
  <button name="next">Next step</button>
  <span class="Demo-status"></span>
</div>
<div class="Demo-container">
  <section class="Grid Grid--headlines">
    <h1 class="Grid-title">Headlines</h1>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <article class="Story"></article>
    <section class="FastNews"></section>
</div>
<pre class="Demo-logs"></pre>
              
            
!

CSS

              
                body {
  margin: 20px;
  font: normal 16px/1.4 sans-serif;
  background: floralwhite;
  color: #222;
}

.Demo-controls {
  padding: 6px 10px;
  margin-bottom: 20px;
  background: lightgrey;
  border: 1px solid silver;
  font-size: 14px;
  text-align: center;
}

.Demo-controls button {
  font-size: inherit;
}

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

.Grid {
}

/* visually hide the title */
.Grid-title {
  position: absolute;
  width: 0;
  height: 0;
  clip: rect(0 0 0 0);
}

.Story {
  min-height: 60px;
}

/* colour the stories in */
.Story:nth-of-type(1),
.Story:nth-of-type(2) {
  background: lightsalmon;
}

.Story:nth-of-type(n+3):nth-of-type(-n+7) {
  background: darkseagreen;
}

.Story:nth-of-type(n+8):nth-of-type(-n+11) {
  background: steelblue;
}

.FastNews {
  background: tomato;
}

/* layout */
.step-1 .Grid {
  display: grid;
  grid-gap: 20px;
  grid-template-columns: repeat(12, 1fr);
}

.step-2 .Story:nth-of-type(1) {
  grid-column: span 4;
}

.step-2 .Story:nth-of-type(2) {
  grid-column: span 5;
}

.step-3 .FastNews {
  grid-row: 1 / span 1;
  grid-column: 10 / span 3;
}

.step-4 .Story:nth-of-type(n+3):nth-of-type(-n+6) {
  grid-column: span 3;
}

.step-4 .Story:nth-of-type(7) {
  grid-column: span 6;
}

.step-5 .Story:nth-of-type(6) {
  grid-column: 1 / span 3 !important;
}

.step-6 .Story:nth-of-type(n+8):nth-of-type(-n+11) {
  grid-column: 10 / span 3;
}

.step-7 .Grid {
  grid-auto-flow: dense;
}

.step-8 .Story:nth-of-type(n+3):nth-of-type(-n+7) {
  grid-row: span 2;
}

              
            
!

JS

              
                var messages = [
  '1. Define a 12 column grid but skip declaring any rows',
  '2. Size the first two stories by declaring how many columns they span',
  '3. Explicitly define the grid area for the sub-section',
  '4. Declare the column spans for the next 5 stories',
  '5. Clear the right-hand-side by wrapping stories onto a new row',
  '6. Instruct the final 4 stories to start from the 10th grid line and span the remaining columns',
  '7. Set the grid algorithm to dense',
  '8. Make the stories on the left span multiple rows'
]

var steps = messages.length
var current = 0

var next = document.querySelector('button[name=next]')
var prev = document.querySelector('button[name=prev]')
var stat = document.querySelector('.Demo-status')
var logs = document.querySelector('.Demo-logs')

function step (to) {
  if (to > current) {
    document.body.classList.add('step-' + to)
  } else {
    document.body.classList.remove('step-' + current)
  }

  next.disabled = to >= steps
  prev.disabled = to <= 0

  current = to
  
  status()
}

function status () {
  stat.textContent = 'Step ' + current + ' of ' + steps
  
  logs.textContent = messages.slice(0, current).join('\n')
}

next.onclick = function () {
  if (current < steps) {
    step(current + 1)
  }
}

prev.onclick = function() {
  if (current > 0) {
    step(current - 1)
  }
}

step(0)

var support = window.CSS && CSS.supports('display', 'grid')

if (!support) {
  var p = document.createElement('p')
  
  p.innerHTML = '<strong>Your browser does not appear to support grid layout. You may need <a href="https://igalia.github.io/css-grid-layout/enable.html">to enable it</a>.</strong>'
  
  document.body.insertBefore(p, document.body.firstChild);
}

              
            
!
999px

Console