Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

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.

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

              
                <!-- you can place this modal window anywhere in the content -->
<div class="modal-wrapper">
  <div class="modal">
    <div class="close-modal">X</div>
    <div id="modal-content"></div>
  </div>
</div>
<!-- end modal-wrapper -->

<div id="wrapper">
  <button href="#" class="modal-link">Open Modal</button>
  <!-- our JS calls the .modal-link class -->
</div>

<div class="show-in-modal hide">
  <h1>This is the modal content</h1>
</div>
<!-- our JS calls the .show-in-modal class -->
              
            
!

CSS

              
                // codepen only styles
.modal-link {
  width: 150px;
  height: 40px;
  margin: auto;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  border: none;
  border-radius: 5px;
  background: #00bfff;
  color: white;
  text-transform: uppercase;
  
}

// Styles for functionality
@media only screen and (min-width: 768px) {
  .hide {
    display: none;
  }
  .show {
    display: block!important;
  }
    .modal-wrapper {
        z-index: 999;
        position: absolute;
        left: calc((100vw - 600px)/2); // center the modal horizontally
    }

    .modal {
        display: none;
        position: relative;
        width: 600px;
        min-height: 300px;
        padding: 20px 15px;
        background: #EEEEEE;
        color: #000000;
        text-align: center;

        .close-modal {
            position: absolute;
            top: 20px;
            right: 15px;
            cursor: pointer;
        }

        h1 {
            font-size: 56px;
            margin: 35px 0;
        }

        .entry-content {
            p {
                font-size: 16px;
            }
        }
    }
}
// end of media query

@media only screen and (min-width: 1030px) {}
// end of media query
              
            
!

JS

              
                jQuery(document).ready(function($) {
  // Close modal 
  $('.close-modal').click(function() {
    $('.modal').toggleClass('show');
  });

  // Detect windows width function
  var $window = $(window);

  function checkWidth() {
    var windowsize = $window.width();
    if (windowsize > 767) {
      // if the window is greater than 767px wide then do below. we don't want the modal to show on mobile devices and instead the link will be followed.

      $(".modal-link").click(function(e) {
        var modalContent = $("#modal-content");
        var post_link = $('.show-in-modal').html(); // get content to show in modal
        //var post_link = $(this).attr("href"); // this can be used in WordPress and it will pull the content of the page in the href
        
        e.preventDefault(); // prevent link from being followed
        
        $('.modal').addClass('show', 1000, "easeOutSine"); // show class to display the previously hidden modal
        modalContent.html("loading..."); // display loading animation or in this case static content
        modalContent.html(post_link); // for dynamic content, change this to use the load() function instead of html() -- like this: modalContent.load(post_link + ' #modal-ready')
        $("html, body").animate({ // if you're below the fold this will animate and scroll to the modal
          scrollTop: 0
        }, "slow");
        return false;
      });
    }
  };

  checkWidth(); // excute function to check width on load
  $(window).resize(checkWidth); // execute function to check width on resize
});
              
            
!
999px

Console