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

              
                <button class="modal-open">Open modal box</button>
<div class="modal-box">
    <div class="modal-box-content">
        <ul>
            <li><a href="#">One</a></li>
            <li><a href="#">Two</a></li>
            <li><a href="#">Three</a></li>
            <li><a href="#">Four</a></li>
            <li><a href="#">Five</a></li>
        </ul>
    </div>
    <button class="modal-close"><span class="visuallyhidden">Close modal box</span></button>
</div>
              
            
!

CSS

              
                $ease: cubic-bezier(0.165, 0.84, 0.44, 1);
$highlight-color: #505050;

@mixin absolute-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

body {
    font-family: sans-serif;
    background-color: #1d1f20;
}

.modal-open {
    padding: 10px 0;
    font-weight: 300;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #fff;
    border: 0;
    outline: none;
    background-color: transparent;
    @include absolute-center;
    &:before,
    &:after {
        content: "";
        position: absolute;
        top: 100%;
        left: 0;
        height: 2px;
        transition: width 400ms $ease;
    }
    &:before {
        width: 100%;
        background-color: lighten($highlight-color, 30%);
    }
    &:after {
        width: 0;
        background-color: $highlight-color;
    }
    &:hover:after {
        width: calc(100% + 1px);
    }
}

.modal-box {
    position: absolute;
    overflow: hidden;
    width: 0;
    height: 2px;
    color: #fff;
    background-color: $highlight-color;
    transition: width 400ms 400ms $ease, left 400ms 400ms $ease, height 400ms 0ms $ease, top 400ms 0ms $ease;
    &.is-open {
        transition: width 400ms 0ms $ease, left 400ms 0ms $ease, height 400ms 400ms $ease, top 400ms 400ms $ease;
        li {
            opacity: 1;
        }
        .modal-close {
            opacity: 1;
            transition: all 500ms 700ms;
        }
    }
    ul {
        position: absolute;
        top: 50%;
        left: 50%;
        margin: 0;
        padding: 30px;
        list-style-type: none;
        transform: translate(-50%, -50%);
    }
    li {
        position: relative;
        margin: 20px 0;
        text-align: center;
        opacity: 0;
        transition: all 200ms;
    }
    a {
        position: relative;
        font-weight: 300;
        text-decoration: none;
        letter-spacing: 3px;
        text-transform: uppercase;
        color: #fff;
        &:before,
        &:after {
            content: "";
            position: absolute;
            top: 100%;
            left: 0;
            height: 2px;
            transition: width 400ms $ease;
        }
        &:after {
            width: 0;
            background-color: #fff;
        }
        &:hover:after {
            width: 100%;
        }
    }
    @for $i from 1 through 5 {
        &.is-open li:nth-child(#{$i}) {
            transition: all 500ms 500ms + (75ms * $i);
        }
    }
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 15px;
    height: 15px;
    padding: 0;
    border: 0;
    outline: none;
    opacity: 0;
    background-color: transparent;
    transform: rotate(-45deg);
    &:before,
    &:after {
        content: "";
        display: block;
        position: absolute;
        top: 50%;
        left: 0;
        width: 15px;
        height: 3px;
        background-color: #fff;
        transform: translate(-50%, -50%);
    }
    &:after {
        width: 3px;
        height: 15px;
    }
}

.visuallyhidden {
    position: absolute;
    overflow: hidden;
    clip: rect(0 0 0 0);
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
}

              
            
!

JS

              
                var $trigger = $('.modal-open');
var $close = $('.modal-close');
var $modal = $('.modal-box');

$(window).on('resize', function() {
    var top = $trigger.offset().top + $trigger.outerHeight();
    var left = $trigger.offset().left;
    var width = $trigger.outerWidth();
    $trigger.attr({
        'data-top': top,
        'data-left': left,
        'data-width': width
    });
    $modal.css({
        top: top,
        left: left
    });
}).trigger('resize');

$trigger.on('click', function() {
    $modal.css({
        top: 0,
        left: 0,
        width: '100%',
        height: '100%'
    }).addClass('is-open');
});

$close.on('click', function() {
    var top = $trigger.offset().top + $trigger.outerHeight();
    var left = $trigger.offset().left;
    $modal.css({
        top: top,
        left: left,
        width: 0,
        height: '2px'
    }).removeClass('is-open');
});
              
            
!
999px

Console