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" x-data="settings" @resize.window="checkVW(innerWidth)">
    <div 
         class="settings"
         @click.outside="open = false"
         x-cloak
        >
        <button type="button" 
                @click="open =! open" 
                :class="{ active: open }"
                >
            <svg xmlns="http://www.w3.org/2000/svg" 
                 fill="none" viewBox="0 0 24 24" 
                 stroke="currentColor" 
                 stroke-width="2">
              <path stroke-linecap="round" stroke-linejoin="round" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
              <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />

            </svg>
        </button>
        
        <div x-show="open" x-transition class="settings__container">
            <header>
                <div>
                    <p>Minimum screen width to work: <span>640px<span></p>
                    <p>Your screenwidth is <span x-text=`${vw}px`></span></p>
                </div>
                <button type="button" @click="open = false">X</button>
            </header>
                   
            <div class="form">
                <label>
                    Images in column: <span x-text="ic"></span>
                    <input type="range" min="1" max="4" step="1" x-model.number="ic">
                </label>
                <label>
                    Image height: <span x-text="ih"></span> px
                    <input type="range" min="150" max="1000" step="25" x-model.number="ih">
                </label>
                <label>
                    Big image width: <span x-text="iw"></span> %
                    <input type="range" min="30" max="80" step="5" x-model.number="iw">
                </label>
                <label>
                    Image spacing: <span x-text="is"></span>
                    <input type="text" x-model="is">
                </label>
                <label>
                    Border radius: <span x-text="r"></span>
                     <input type="text" x-model="r">
                </label>
                <label>
                    Transition on hover: <span x-text="tr"></span> ms
                     <input type="range" min="0" max="1000" step="50" x-model.number="tr">
                </label>
                <button @click.prevent="updateValues">save</button>
            </div>
                
        </div>        
    </div>
    
    <!-- gallery -->
    <div class="gallery">
        <figure>
            <img src='https://images.unsplash.com/photo-1557180295-76eee20ae8aa?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI5MDM&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 1</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
        
        <figure>
            <img src='https://images.unsplash.com/photo-1567653418876-5bb0e566e1c2?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI5MDM&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 2</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
        
        <figure>
            <img src='https://images.unsplash.com/photo-1517816428104-797678c7cf0c?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI4ODE&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 4</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
        
        <figure>
            <img src='https://images.unsplash.com/photo-1494253109108-2e30c049369b?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI3NzM&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 3</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
        
        <figure>
            <img src='https://images.unsplash.com/photo-1557180295-76eee20ae8aa?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI5MDM&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 1</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
        
        <figure>
            <img src='https://images.unsplash.com/photo-1567653418876-5bb0e566e1c2?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI5MDM&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 2</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
        
        <figure>
            <img src='https://images.unsplash.com/photo-1494253109108-2e30c049369b?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI3NzM&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 3</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
        
        <figure>
            <img src='https://images.unsplash.com/photo-1517816428104-797678c7cf0c?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NTc1NTI4ODE&ixlib=rb-1.2.1&q=80' alt='' loading="lazy">
            <figcaption>
                <h3>Item 4</h3>
                <p>Lorem ipsum dolor sit amet.</p>
            </figcaption>
        </figure>
    </div>
    <!-- gallery end -->        
</div>
              
            
!

CSS

              
                * {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
html,
body {
    height: 100%;
}
body {
    background-color: #1B2021;
    font-size: 14px;
}
[x-cloak] { display: none; }

.wrapper {
    display: grid;
    place-items: center;
    min-height: 100%;
    padding-top: 6rem;
    padding-bottom: 3rem;
    
    .settings {
        $gray: lighten(#1B2021, 10%);
        position: fixed;
        right: 1rem;
        top: 1rem;
        z-index: 10;
        
        .form {
            label {
                color: white;
                span{ 
                    color: #fff;
                    background-color: #F25757; 
                    padding: 2px 4px;
                    border-radius: 2px;
                }
            }

            input {
                display: block;
                margin: .75rem 0 1.6rem;
                
                &[type="text"] {
                    padding: .25rem .5rem;
                }
            }
            button {
                border-radius: 2px;
                width: 80px;
                color: #fff;
                text-transform: uppercase;
                outline: none;
                box-shadow: none;
                &:active,
                &:hover{
                    background-color: #222;
                }
            }
        }
        
        button {
            display: flex;
            align-items: center;
            justify-content: center;
            color: #1B2021;
            min-height: 44px;
            min-width: 44px;
            background: #F25757;
            border-radius: 50%;
            border: none;
            box-shadow: 0 0 10px rgb(#F25757, .5);
            cursor: pointer;
            outline: 2px solid rgb(#F25757, .25);
            outline-offset: -1px;
            transition: all .2s ease;

            svg {
                color: white;
                height: 1.5rem;
                width: 1.5rem;
            }
            
            &.active {
                outline-offset: 5px;
            }
        }
        
        &__container {
            background-color: $gray;
            position: absolute;
            top: 4rem;
            right: 1rem;
            width: 450px;
            max-width: calc(100vw - 3rem);
            padding: 20px;
            box-shadow: 0 5px 15px rgb(black, .5);
            border-radius: 4px;
            max-height: calc(100vh - 6rem);
            overflow-y: auto;
            
            header {
                display: flex;
                align-items: center;
                width: 100%;
                padding-bottom: 1rem;
                margin-bottom: 1rem;
                border-bottom: 2px solid gray;
                
                div { margin-right: 2rem; }
                p {
                    color: gray;
                    span { color: #ccc; font-weight: bold; }
                    + p { margin-top: 5px; color: #ccc; }
                }
                
                button {
                    height: 36px;
                    width: 36px;
                    background-color: black;
                    outline: none;
                    color: white;
                    margin-left: auto;
                    box-shadow: none;
                }
            }
        }
    }
}

// Gallery Styling
.gallery {    
    // only for JS settings
    --tr: 150ms;
    
    // Gallery Settings
    $imgCount: 2;
    $imgBigWidth: 60%;
    $imgHeight: 500px; 
    $galleryWidth: 90%;
    $calcCount: #{$imgCount * 2};

    $radius: 0.5rem;
    $imgSpacing: clamp(10px, 3vw, 3rem);
    $transition: var(--tr);

    $bg: #1B202150;
    $txt: #f2f2f2;

    $grayscale: false;
    $txtSlide: true;
    
    // gallery settings end
   
    display: flex;
    flex-wrap: wrap;
    width: $galleryWidth;
    margin: auto;
    
    @media(min-width: 1600px) {
        max-width: 1400px;
    }

    > figure {        
        position: relative;
        height: $imgHeight;
        margin: 0;
        padding: 0;
        width: 100%;
        border-radius: $radius;
        overflow: hidden;
        
        img {
            display: block;
            max-width: 100%;
            width: 100%;
            height: $imgHeight;
            max-height: 100%;
            object-fit: cover;
            object-position: center;
        }

        > figcaption {
            display: block;
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            color: $txt;
            line-height: 1.6;
            padding: $imgSpacing;
            max-height: 100%;
            background-color: $bg;
            z-index: 1;
            
            > h3 {
                letter-spacing: 1px;
                color: #fff;
                font-size: 1.25em;
            }
        }

        @media (max-width: 639px) {
            &:not(:first-child) {
                margin-top: $imgSpacing;
            }
        }
    
        @media (min-width: 640px) {
            flex-grow: 1;
            flex-shrink: 1;
            flex-basis: calc(#{100% - $imgBigWidth} / #{$imgCount - 1} - #{$imgSpacing});
        
            &:not(:nth-child(-n + #{$imgCount})) {
                margin-top: $imgSpacing;
            }
    
            &:not(:nth-child(#{$imgCount}n)) {
                margin-right: $imgSpacing;
            }

            &:last-child {
                margin-right: 0;
            }

            &:nth-child(#{$calcCount}n + 1),
            &:nth-child(#{$calcCount}n + #{$calcCount}) {
                flex-basis: calc(#{$imgBigWidth} - #{$imgSpacing});
            }
        }

        @if $txtSlide == true {
            > figcaption {
                transition: transform var(--tr) ease-in-out;
                transform: translate3d(0, 100%, 0);
            }
            &:hover > figcaption {
                transform: none;
            }
        }

        @if $grayscale == true {
            @media (hover:hover) {
                img {
                    filter: grayscale(.8);
                    transition: filter var(--tr) ease-in-out;
                }
                &:hover img {
                    filter: none;
                }
            }
        }
    }

}


              
            
!

JS

              
                import Alpine from 'https://unpkg.com/alpinejs@3.x.x/dist/module.esm.js';
// console.log(Alpine)

Alpine.data('settings', () => ({
    open: false, 
    lightbox: false,
    ic: 2,
    ih: 500,
    iw: 60,
    is: 'clamp(10px, 3vw, 3rem)',
    r: '0.5rem',
    vw: 640,
    tr: 150,
    gl: document.querySelectorAll('.gallery > *'),
    
    init() {
        this.checkVW(window.innerWidth);
    },
    
    get updateValues() {
        if (this.vw < 640) return;
        
        // Reset all style attributes
        this.resetAttributes();
        
        // general styling to all elements
        this.gl.forEach((item,i) => {
            // reset default css
            item.style.marginTop = '0';
            item.style.marginRight = '0';
            item.style.flexBasis = 'auto';
            // set new styling
            item.style.borderRadius = this.r;
            item.style.height = `${this.ih}px`;
            item.querySelector('img').style.height = `${this.ih}px`;
            item.style.flexBasis = `calc(${100 - this.iw}% / ${this.ic-1} - ${this.is})`;
        });
        
        // set transition speed
        document.querySelector('.gallery').style.setProperty('--tr', `${this.tr}ms`);
        
        // set margin top to elements
        document.querySelectorAll(`.gallery > *:not(:nth-child(-n + ${this.ic})`).forEach(item => {
            item.style.marginTop = this.is
        });
        
        // set margin right to elements
        document.querySelectorAll(`.gallery > *:not(:nth-child(${this.ic}n)`).forEach(item => {
             item.style.marginRight = this.is
        });
        
        // reset margin right to last element
        document.querySelector('.gallery > *:last-child').style.marginRight = '0';
        
        // calc flex-basis to elements with big images
        document.querySelectorAll(`.gallery > *:nth-child(${this.ic*2}n + 1)`).forEach(item => {
            item.style.flexBasis = `calc(${this.iw}% - ${this.is})`
        });
        
        document.querySelectorAll(`.gallery > *:nth-child(${this.ic*2}n + ${this.ic*2})`).forEach(item => {
            item.style.flexBasis = `calc(${this.iw}% - ${this.is})`
        });
    },
    
    resetAttributes() {
        this.gl.forEach(item => {
            item.removeAttribute('style')
            item.querySelector('img').removeAttribute('style')
        });
    },
    
    checkVW(width) {
        this.vw = width;
        if (this.vw < 640) this.resetAttributes();
    },
}));

Alpine.start();
              
            
!
999px

Console