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

              
                <header>
    <h1>Cool Sidebar</h1>
    
</header>

<!-- NAVIGATION -->
<nav id="nav" class="nav">
    <div id="nav_icon" class="nav_icon">
        <svg class="shape_container top">
            <path class="icon_shape" d="M 0 0 L 20 0 Q 0 0 0 20 Z" />
        </svg>
        <span>MENU</span><i class="fas fa-angle-right"></i>
        <svg class="shape_container bottom">
            <path class="icon_shape" d="M 0 0 L 20 0 Q 0 0 0 20 Z" />
        </svg>
    </div>

    <ul>
        <li>
            <a href="#"><i class="fas fa-home"></i>Home</a>
        </li>
        <li>
            <a href="#sa"><i class="fas fa-hat-cowboy-side"></i>About</a>
        </li>
        <li>
            <a href="#sp"><i class="far fa-gem"></i>Projects</a>
        </li>
        <li>
            <a href="#sc"><i class="fas fa-globe-europe"></i>Customers</a>
        </li>
        <li>
            <a href="#ser"><i class="fas fa-network-wired"></i>Service</a>
        </li>
    </ul>
</nav>

<!-- MAIN -->
<main class="main">
    <section id="sa" aria-labelledby="about">
        <h2 id="about">About</h2>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
    </section>
    <section id="sp" aria-labelledby="projects">
        <h2 id="projects">Projects</h2>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
    </section>
    <section id="sc" aria-labelledby="customer">
        <h2 id="customer">Projects</h2>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
    </section>
    <section id="ser" aria-labelledby="service">
        <h2 id="service">Service</h2>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
        <p>
            Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto dolorum voluptatum quae omnis, facere, accusamus animi consequatur molestias corrupti debitis, natus neque
            rerum. Error facilis reprehenderit harum beatae impedit praesentium tempore vitae exercitationem fugit laudantium aspernatur voluptas non consectetur voluptatem necessitatibus hic
            neque unde atque cumque ipsum veritatis, eligendi esse?
        </p>
    </section>
</main>
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body,
html {
    height: 100%;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

nav {
    > ul {
        list-style: none;
        scrollbar-width: none;
        
        &::-webkit-scrollbar {
            width: 0;
        }
    }
    
    a {
        text-decoration: none;
    }
}

section {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 5rem;

    p, 
    h2 {
        max-width: 90ch;
        margin-bottom: 2rem;
    }
    
    &:nth-child(even) {
        background-color: #f2f2f2;
    }
}

header {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: relative;
    background-color: #ff5964;
    background-image: linear-gradient(120deg, rgb(48, 207, 208) 10%, rgb(51, 8, 103) 95%);

    > h1 {
        text-transform: uppercase;
        text-align: center;
        font-size: 4rem;
        color: #fff;
        text-shadow: 0 0 3rem rgba(white, 0.25), 0 0 1rem rgba(white, 0.5);
        position: relative;
    }

    &::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: url(https://assets.codepen.io/1753016/mountains.jpg) center center/cover;
        opacity: 0.5;
    }
}

//* SIDEBAR / NAVIGATION *//
.nav {
    // colors
    $nav_bg: #ff5964;
    $nav_link: #fff;
    $time: .2s;
    
    position: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100%;
    width: 250px;
    background-color: $nav_bg;
    transform: translateX(-100%);
    transition: transform $time ease;
    z-index: 100;

    &.open {
        transform: translateX(0);
        box-shadow: 5px 0 10px rgba(black, 0.25);
    }

    &_icon {
        position: absolute;
        display: flex;
        justify-content: center;
        align-items: center;
        top: 50%;
        right: -40px;
        width: 40px;
        height: 40px;
        border-radius: 0 10px 10px 0;
        border-right: 1px solid lighten($nav_bg, 10%);
        background-color: $nav_bg;
        cursor: pointer;
        box-shadow: 5px 0 5px rgba(black, 0.25);
        transform: translateY(-50%);
        transition: all 0.5s;

        > i {
            pointer-events: none;
            color: $nav_link;
            font-size: 1rem;
            transition: transform $time ease;

            &.rotate {
                transform: rotate(180deg);
            }
        }

        > span {
            pointer-events: none;
            font-size: 0;
            color: $nav_link;
            transform: rotate(90deg);
            transition: all $time;
        }

        > .shape_container {
            position: absolute;
            left: 0;
            height: 20px;
            width: 20px;
            z-index: 1;

            &.bottom {
                bottom: -20px;
            }
            &.top {
                top: -20px;
                transform: rotateX(180deg);
            }
            > .icon_shape {
                fill: $nav_bg;
            }
        }

        &.mouseDistance {
            transition: all $time, top 0s;
        }

        &.mouseDistanceCloser {
            height: 60px;
            width: 60px;
            right: -60px;
            border-radius: 0 30px 30px 0;

            > .shape_container {
                height: 40px;
                width: 40px;
                &.top {
                    top: -40px;
                }
                &.bottom {
                    bottom: -40px;
                }
            }

            > span {
                font-size: 10px;
            }

            > i {
                font-size: 1.5rem;
            }
        }

        &:hover {
            box-shadow: none;
        }
    }

    > ul {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 1rem 0;
        overflow: auto;
    }

    > ul > li {
        width: 100%;
        min-height: 3rem;

        &:not(:last-child) {
            margin-bottom: 1.5rem;
        }

        > a {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            width: 100%;
            height: 100%;
            color: darken($nav_bg, 40%);
            text-shadow: 0 1px 1px lighten($nav_bg, 5%);
            text-transform: uppercase;

            &:hover {
                color: $nav_link;
            }

            > i {
                display: block;
                font-size: 1.5rem;
                margin-bottom: .5rem;
                color: currentColor;
            }
        }
    }
}
              
            
!

JS

              
                /**
 ** HELPER FUNCTIONS
 */
const qSel = (obj) => document.querySelector(obj);
const qSelAll = (obj) => document.querySelectorAll(obj);

/**
 ** GLOBAL VARIABLES
 */
const nav = qSel('#nav');
const nav_container = qSel('#nav_icon');
const nav_icon = qSel('#nav_icon > i');
const nav_links = qSelAll('#nav > ul > li > a');

/**
 ** OPEN SIDEBAR
 */
nav_container.addEventListener('click', () => {
    if (nav.classList.contains('open')) {
        closeSidebar();
        return;
    }
    
    nav.classList.add('open');
    nav_icon.classList.add('rotate');
});

/**
 ** CLOSE SIDEBAR AFTER CLICK ON LINK 
 */
nav_links.forEach(link => {
    link.addEventListener('click', e => {
        e.stopPropagation();
        closeSidebar();
    });
});

/**
 ** MOUSE TRACK EVENT 
 */
if (innerWidth > 980) {
    // Mouse move event
    window.addEventListener('mousemove', e => {
        const mouseY = Math.round((e.y * 100) / innerHeight);
        const mouseX = Math.round((e.x * 100) / innerWidth);

        // Detect mouse position
        if (!nav.classList.contains('open') && mouseX <= 20) {
            nav_container.style.top = `${mouseY}%`;
            nav_container.classList.add('mouseDistance');
        } else {
            nav_container.classList.remove('mouseDistance');
            nav_container.style.top = '50%';
        }
        
        // Check mouse distance to nav
        mouseX <= 10 ? 
            nav_container.classList.add('mouseDistanceCloser') : 
            nav_container.classList.remove('mouseDistanceCloser');
            
        if (nav.classList.contains('open') || (mouseY >= 90 || mouseY <= 10)) resetNavIcon();
    }); 
    
    // Mouse leave window
    document.addEventListener('mouseleave', () => {
        closeSidebar();
        resetNavIcon();
    });
};

/**
 ** CLOSE SIDEBAR WHILE CLICKING OUTSIDE
 */
window.addEventListener('click', e => {
    e.stopPropagation();
    if (!nav.classList.contains('open')) return;
    if (!e.target.closest('nav')) {
        closeSidebar();
        resetNavIcon();
    }
});

/**
 ** CLOSE SIDEBAR
 */
function closeSidebar() {
    nav.classList.remove('open');
    nav_icon.classList.remove('rotate');
}

/**
 ** RESET NAV ICON
 */
function resetNavIcon() {
    nav_container.classList.remove('mouseDistance');
    nav_container.classList.remove('mouseDistanceCloser');
    nav_container.style.top = '50%';
}
              
            
!
999px

Console