cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <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>
            
          
!
            
              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;
}

            
          
!
            
              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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console