css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <section class="page">
  <p>Lorem <a href="#" class="js-modal" data-toggle-modal="dialog1">ipsum dolor sit amet</a>, consectetur adipiscing elit. Etiam sit amet ornare odio. Nulla sit amet ex porttitor, vehicula ex quis, fringilla magna. Praesent bibendum ullamcorper libero, sit amet interdum dui elementum eget. Nunc ac blandit orci, at lobortis felis. Proin vel lectus nunc. Donec dapibus commodo dui, et bibendum purus sagittis id. Morbi sagittis massa vitae justo ultrices suscipit. Proin sed lacinia elit. Nunc orci tellus, auctor <a href="#" class="js-modal" data-toggle-modal="dialog1">vel elementum non</a>, maximus ac felis. In nec lobortis erat. Quisque pharetra lacus ac justo hendrerit, vel viverra ante molestie. Quisque nec ex urna. Ut lacinia, felis non faucibus elementum, nisi nisl porttitor erat, vitae elementum turpis odio non orci. Duis mollis vel tortor vitae tincidunt. Curabitur elementum metus in varius aliquam. Integer pellentesque, nisi at tempus eleifend, mi nisi ullamcorper nisi, ac placerat magna tellus a mi.</p>

<p>Vivamus sodales tempus sagittis. Quisque sed urna ut odio cursus cursus nec eget arcu. Vestibulum id lacinia risus. <a href="#" class="js-modal" data-toggle-modal="dialog1">Cras pellentesque</a> metus a dolor luctus volutpat. Aliquam maximus, magna vel congue condimentum, ex justo porta massa, faucibus sodales turpis tellus egestas nisl. Vestibulum ac semper lacus. Etiam iaculis ultrices ipsum, at dignissim nunc bibendum in. Pellentesque pellentesque suscipit purus rhoncus tincidunt.</p>

  <p>In a arcu lacus. <a href="#" class="js-modal" data-toggle-modal="dialog1">Mauris lectus nisi</a>, convallis vel orci eget, gravida feugiat sem. Mauris mollis hendrerit odio, id congue urna luctus et. Sed eu elementum massa, id blandit tortor. In hac habitasse platea dictumst. Nullam pharetra mattis arcu, nec malesuada arcu dapibus et. Praesent vestibulum eget nibh sit amet aliquam. Sed porttitor in velit in scelerisque. Nullam nec molestie purus. Pellentesque euismod nibh ipsum.</p>

  <p>Sed condimentum mollis elit et <a href="#" class="js-modal" data-toggle-modal="dialog1">imperdiet</a>. Pellentesque ac bibendum urna. In sit amet tristique velit, quis ultricies justo. Etiam sollicitudin consequat nisi, non fringilla ligula dignissim in. Ut ipsum ante, gravida ut eleifend at, auctor at nisl. Etiam consectetur feugiat dui, ut condimentum nibh semper sed. Integer quis <a href="#" class="js-modal" data-toggle-modal="dialog1">finibus sapien</a>. Aliquam erat volutpat. Donec quis rhoncus lectus. Nam consequat interdum mauris, in convallis ante posuere eu.</p>

<p>In gravida posuere nunc, vitae iaculis justo fermentum vitae. Sed vitae rhoncus magna. Aliquam dignissim hendrerit lacus, ac ultrices magna. Proin gravida, urna in maximus pretium, <a href="#" class="js-modal" data-toggle-modal="dialog1">libero magna placerat tortor</a>, non ornare nisl odio vitae sem. Mauris interdum arcu nisi, quis pharetra ex sodales vel. Donec facilisis faucibus felis eget imperdiet. In bibendum quam nec ex vehicula accumsan.</p>
</section>

<div class="modal"
     data-modal="dialog1"
     role="dialog" 
     aria-labelledby="modal-label"
     aria-describedby="modal-description"
     aria-hidden="false">
  <a href="#" class="modal__toggle js-modalClose">x</a>
  <h2 class="modal__title" id="modal-label">
    My modal title
  </h2>
  <div class="modal__inner">
    <p class="modal__intro" id="modal-description">This paragraph describes the content of this modal.</p>
    <p>In gravida posuere nunc, vitae iaculis justo fermentum vitae. Sed vitae rhoncus magna. Aliquam dignissim hendrerit lacus, ac ultrices magna. Proin gravida, urna in maximus pretium, libero magna placerat tortor, non ornare nisl odio vitae sem. Mauris interdum arcu nisi, quis pharetra ex sodales vel. Donec facilisis faucibus felis eget imperdiet. In bibendum quam nec ex vehicula accumsan.</p>
        <p>In gravida posuere nunc, vitae iaculis justo fermentum vitae. Sed vitae rhoncus magna. Aliquam dignissim hendrerit lacus, ac ultrices magna. Proin gravida, urna in maximus pretium, libero magna placerat tortor, non ornare nisl odio vitae sem. Mauris interdum arcu nisi, quis pharetra ex sodales vel. Donec facilisis faucibus felis eget imperdiet. In bibendum quam nec ex vehicula accumsan.</p>
            <p>In gravida posuere nunc, vitae iaculis justo fermentum vitae. Sed vitae rhoncus magna. Aliquam dignissim hendrerit lacus, ac ultrices magna. Proin gravida, urna in maximus pretium, libero magna placerat tortor, non ornare nisl odio vitae sem. Mauris interdum arcu nisi, quis pharetra ex sodales vel. Donec facilisis faucibus felis eget imperdiet. In bibendum quam nec ex vehicula accumsan.</p> 
            <p>In gravida posuere nunc, vitae iaculis justo fermentum vitae. Sed vitae rhoncus magna. Aliquam dignissim hendrerit lacus, ac ultrices magna. Proin gravida, urna in maximus pretium, libero magna placerat tortor, non ornare nisl odio vitae sem. Mauris interdum arcu nisi, quis pharetra ex sodales vel. Donec facilisis faucibus felis eget imperdiet. In bibendum quam nec ex vehicula accumsan.</p>
                <p>In gravida posuere nunc, vitae iaculis justo fermentum vitae. Sed vitae rhoncus magna. Aliquam dignissim hendrerit lacus, ac ultrices magna. Proin gravida, urna in maximus pretium, libero magna placerat tortor, non ornare nisl odio vitae sem. Mauris interdum arcu nisi, quis pharetra ex sodales vel. Donec facilisis faucibus felis eget imperdiet. In bibendum quam nec ex vehicula accumsan.</p> 
                <p>In gravida posuere nunc, vitae iaculis justo fermentum vitae. Sed vitae rhoncus magna. Aliquam dignissim hendrerit lacus, ac ultrices magna. Proin gravida, urna in maximus pretium, libero magna placerat tortor, non ornare nisl odio vitae sem. Mauris interdum arcu nisi, quis pharetra ex sodales vel. Donec facilisis faucibus felis eget imperdiet. In bibendum quam nec ex vehicula accumsan.</p> 
  </div>
</div>
            
          
!
            
              $color-modal-bg: #634fa0;
$color-modal-fg: #FFFFFF;
$color-modal-button-bg: darken(#634fa0, 20%);

// Mixing to make breakpoints a little easier. Can be expanded with any breakpoints as needed.
@mixin breakpoint() {
  @media (min-width: 768px)  { @content ; }
}

body {
  font-family: 'Yanone Kaffeesatz', sans-serif;
  font-size: 30px;
  background-color: lighten($color-modal-bg, 25%);
  width: 100%;
}

.page {
  max-width: 800px;
  margin: 10px;
  
  @include breakpoint {
    margin: 20px auto;
  }
  
  p {
    margin-bottom: 20px;
    line-height: 1.5;
  }
}

.modal {
  position: fixed;
  overflow: hidden;
  z-index: 99;
  margin: 0 auto;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: $color-modal-bg;
  opacity: 0.95;
  
  @include breakpoint {
    top: 10%;
    left: 10%;
    right: 10%;
    bottom: 15%;
    border: 2px solid darken($color-modal-bg, 5%);
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); 
  }
  
  &__inner {
    display: block;
    position: absolute;
    padding: 20px;
    color: $color-modal-fg;
    line-height: 1.5;
    top: 54px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    overflow: auto;
    
    @include breakpoint {
      top: 54px;
      left: 20px;
      right: 20px;
      bottom: 20px;
      padding: 0 20px 0 0;
    }
  }
  
  &__title {
    margin: 10px 0 0 14px;
    color: $color-modal-button-bg;
    font-weight: bold;
  }
    
  &__intro {
    margin-bottom: 20px;
    color: rgba(#FFFFFF, 0.5);
  }
  
  &__toggle {
    display: block;
    position: absolute;
    z-index: 2;
    top: 0;
    right: 0;
    padding: 2px 20px 4px;
    background-color: $color-modal-button-bg;
    color: white;
    border-radius: 0 0 0 50%;
    font-size: 30px;
    cursor: pointer;
    text-decoration: none;
  }
  
  &--hidden {
    display: none;
  }
}

.fixed {
  overflow: hidden;
  
  &:after {
    display: block;
    position: fixed;
    z-index: 2;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    content: "";
    background-color: rgba(#000000, 0.3);
  }
}
            
          
!
            
              $(function() {
  
  var $body = $("body");
  
  // In this demo, the Modal is already open, so we add
  // a class to the body (normally done by toggle)  
  $body.addClass("fixed");
  
  // Handle opening a modal
  $(".js-modal").on("click tap", function(e) { 
    e && e.preventDefault();
    var thisModal = $(this).data("toggle-modal");
    toggleModal( thisModal );
  });
  
  // Hand close button
  $(".js-modalClose").on("click", function(e) {
    e && e.preventDefault();
    toggleModal( $(e.target).parent().data("modal") );   
  });
  
  // Open and close the modal
  function toggleModal( modal ) {
    var $showThisModal = $('[data-modal="' + modal + '"]');
    
    if ( $showThisModal.hasClass("modal--hidden") ) {
      $showThisModal.removeClass("modal--hidden");
      $body.addClass("fixed");
    } else {
      $showThisModal.addClass("modal--hidden");
      $body.removeClass("fixed");
    }
    toggleAttribute("aria-hidden", $showThisModal);
  }
  
  // A little helper for toggling attributes
  function toggleAttribute(attributeName, $element) {
    if ( $($element).attr( attributeName ) === 'true' ) {
      $($element).attr( attributeName, 'false');
    } else {
      $($element).attr( attributeName, 'true');
    }
  };
  
  
})
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console