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="wrapper margin-top-children">
  <h1>Auto grid layout</h1>

  <div class="grid-auto-wrapper">
    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

  </div>

  <p>Our 22rem is more or less magic number which relates to wrapper width.</p>

  <p>In this example I have defined wrapper max-width to 70rem and gap to 2rem.</p>

  <p>Math: 22*3 + 2*2 = 70rem</p>

  <p>In other words when container drops under 70rem, we have 2 column layout. Adjust 22rem depending if you want to have more or less than 3 columns.</p>

  <h2>auto-fill example</h2>
  <div class="grid-auto-wrapper">
    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>
  </div>

  <h2>auto-fit example</h2>
  <div class="grid-auto-wrapper grid-auto-wrapper--auto-fit">
    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

    <article class="card">
      <figure class="image-wrapper">
        <img alt="" src="https://via.placeholder.com/1600x900/cccccc/5c5858?text=Image" width="1600" height="900">
      </figure>

      <div class="card__content">
        <p>Some content of this card example.</p>
      </div>
    </article>

  </div>
</div>
              
            
!

CSS

              
                .grid-auto-wrapper {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  grid-gap: 2rem;
}

.grid-auto-wrapper--auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}

.card {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1), 0 2px 10px rgba(0, 0, 0, 0.08);
}

.card__content {
  padding: 1rem;
}

.wrapper {
  margin: 1rem;
  max-width: 70rem;
}

.margin-top-children > * + * {
  marging-bottom: 0;
  margin-top: 2rem;
}

img {
  height: auto;
  max-width: 100%;
  vertical-align: middle;
}

figure {
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui,
    helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial,
    sans-serif;
}

              
            
!

JS

              
                
              
            
!
999px

Console