cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <h1>CSS Grid Image Gallery</h1>

<p>So here's the deal: if CSS Grid (namely <code>grid-gap</code>) is supported by your browser, you'll have a wonderful image gallery. If that's not the case, you'll still have a wonderful image gallery by the power of Flexbox.</p>

<p>If your browser does not support flexbox… well, err… yeah.</p>

<ul>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="https://picsum.photos/500/350" alt="Picsum.photos Placeholder Image" />
            <figcaption>
                <strong>Media Name</strong>
            </figcaption>
        </figure>
    </li>
</ul>
            
          
!
            
              body {
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    
    margin: 0;
    padding: 1.618em 1em;
    
    background: #f4f4f4;
    color: #434343;
    
    @media screen and (min-width: 50em) {
        padding: 1.618em 2em;
    }
    
    @media screen and (min-width: 70em) {
        padding: 2.618em 9.55%;
    }
}

p {
    font-size: 1.125em;
}

ul {
    list-style: none;

    display: flex;
    flex-wrap: wrap;

    margin: 2.618em 0 0;
    padding: 0;
}

li {
    display: flex;
    flex-direction: column;
    
    border: 1px solid #d8d8d8;
    margin: 0 1.25em 1.25em 0;
    max-width: 18.75em;

    background: white;
}

/**
 * in order to trick MS Edge into using Flexbox
 * I'm looking for support of grid-gap and not
 * for display: grid
 */
@supports (grid-gap: 1.25em) {
    ul {
        display: grid;
        grid-gap: 1.25em;
        
        @media screen and (min-width: 30em) {
            grid-template-columns: repeat(2, 1fr);
        }

        @media screen and (min-width: 50em) {
            grid-template-columns: repeat(3, 1fr);
        }

        @media screen and (min-width: 70em) {
            grid-template-columns: repeat(4, 1fr);
        }

        @media screen and (min-width: 100em) {
            grid-template-columns: repeat(5, 1fr);
        }
    }
    
    li {
        margin: 0;
        max-width: 100%;
    }
}

// Just some reset styling
figure {
    margin: 0;
}

img {
    max-width: 100%;
}

figcaption {
    display: block;
    
    margin: 0 .618em;
    padding: .618em 0;
}

code {
    padding: .125em;
    background: white;
}
            
          
!
999px
Loading ..................

Console