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="button-container">
  <button type="button" data-modal-id="my-modal" class="launch">Trailer Embed</button>
  <button type="button" data-modal-id="my-other-modal" class="launch">Launch second Modal</button>
</div>

<div class="modal-container" id="modal-container">
  
  <div class="modal" id="my-modal">
    <iframe width="560" height="315" src="https://www.youtube.com/embed/XFYWazblaUA" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
    <button type="button" class="close">
<svg width="13px" height="13px" viewBox="0 0 13 13" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 48.2 (47327) - http://www.bohemiancoding.com/sketch -->
    <desc>Created with Sketch.</desc>
    <defs></defs>
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="Close" transform="translate(-29.000000, -47.000000)" fill="#D8D8D8">
            <g id="Close-X-2" transform="translate(29.000000, 47.000000)">
                <path d="M6.36396103,4.94974747 L11.3137085,1.77635684e-15 L12.7279221,1.41421356 L7.77817459,6.36396103 L12.7279221,11.3137085 L11.3137085,12.7279221 L6.36396103,7.77817459 L1.41421356,12.7279221 L-1.42108547e-14,11.3137085 L4.94974747,6.36396103 L-1.24344979e-14,1.41421356 L1.41421356,8.8817842e-16 L6.36396103,4.94974747 Z" id="Combined-Shape"></path>
            </g>
        </g>
    </g>
</svg></button></div>
  
  <div class="modal" id="my-other-modal">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis porttitor felis ac urna elementum, ac tristique lacus malesuada. Integer tempor aliquam efficitur.</p>
    <p>Donec eu est fermentum, consequat mauris id, laoreet nunc. Duis aliquam bibendum dolor at iaculis. Quisque id elementum erat. Nam sed suscipit metus. Sed a eros augue.</p>
    <p>Mauris sed ante fermentum, malesuada risus vel, tincidunt augue. Proin venenatis erat vitae nibh scelerisque, sit amet molestie turpis ultrices.
</p>
    <button type="button" class="close">
<svg width="13px" height="13px" viewBox="0 0 13 13" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 48.2 (47327) - http://www.bohemiancoding.com/sketch -->
    <desc>Created with Sketch.</desc>
    <defs></defs>
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="Close" transform="translate(-29.000000, -47.000000)" fill="#D8D8D8">
            <g id="Close-X-2" transform="translate(29.000000, 47.000000)">
                <path d="M6.36396103,4.94974747 L11.3137085,1.77635684e-15 L12.7279221,1.41421356 L7.77817459,6.36396103 L12.7279221,11.3137085 L11.3137085,12.7279221 L6.36396103,7.77817459 L1.41421356,12.7279221 L-1.42108547e-14,11.3137085 L4.94974747,6.36396103 L-1.24344979e-14,1.41421356 L1.41421356,8.8817842e-16 L6.36396103,4.94974747 Z" id="Combined-Shape"></path>
            </g>
        </g>
    </g>
</svg></button></div>
  
</div>

  <p>You should probably check out this <a target="_blank" href="https://codepen.io/bdnorris/pen/gOpbaxP">accessible modal codepen instead.</p>
              
            
!

CSS

              
                $primary: #0288D1;
$secondary: #CFD8DC;

@mixin button-reset {
  border: none;
  background: none;
  color: inherit;
  padding: 0;
  margin: 0;
  font-family: inherit;
  box-shadow: none;
}

body {
  font-family: 'Fira Sans', sans-serif;
}

p {
  line-height: 1.4;
  text-align: center;
}

.button-container {
  width: 100vw;
  height: 80vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

button.launch {
  @include button-reset;
  padding: 0.666em 1em;
  background-color: $primary;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 1em;
  border-radius: 6px;
}

.modal-container {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.2);
  display: none;
  z-index: 100;
  // Safari issue fixes
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  &.active {
    display: flex;
    justify-content: center;
    align-items: center;
  }
}

.modal {
  display: none;
  opacity: 0;
  padding: 3em;
  margin: auto;
  background-color: white;
  position: relative;
  z-index: 101;
  max-width: 70vw;
  max-height: 70vh;
  overflow: auto;
  // Safari Issue fixes
    -webkit-transform: translate3d(0,0,0);
  &.active {
    display: block;
    opacity: 1;
    animation: slide-in-fwd-top 0.4s cubic-bezier(0.250, 0.460, 0.450, 0.940) both;
  }
  button.close {
    @include button-reset;
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    padding: 0.5em;
  }
}



/* ----------------------------------------------
 * Generated by Animista on 2018-1-9 20:45:42
 * w: http://animista.net, t: @cssanimista
 * ---------------------------------------------- */

/**
 * ----------------------------------------
 * animation slide-in-fwd-top
 * ----------------------------------------
 */

@keyframes slide-in-fwd-top {
  0% {

            transform: translateZ(-1400px) translateY(-800px);
    opacity: 0;
  }
  100% {

            transform: translateZ(0) translateY(0);
    opacity: 1;
  }
}

              
            
!

JS

              
                //https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
// forEach method, could be shipped as part of an Object Literal/Module
function forEach(array, callback, scope) {
  for (var i = 0; i < array.length; i++) {
    callback.call(scope, i, array[i]); // passes back stuff we need
  }
}

// Get all modal buttons into a node-list
var modalButtons = document.querySelectorAll("[data-modal-id]");

// Get all modals into a node-list
var allModals = document.querySelectorAll(".modal");

// Cache a reference to the modal container
var modalContainer = document.getElementById("modal-container");

// Add an event to the container to close
if (typeof modalContainer !== "undefined" && modalContainer) {
  modalContainer.addEventListener("click", function(e) {
    console.log(e.target);
    console.log(this);
    if (e.target === this) {
      closeModal(this, "from screen");
    } else {
      // ignore click because it's not directly on the container screen
    }
  });
}

// run through all modal buttons and add event listeners
if (typeof modalButtons !== "undefined" && modalButtons) {
  forEach(modalButtons, function(index, value) {
    // get the data attribute id
    let modalId = value.getAttribute("data-modal-id");
    // add event listeners to each modal to run our function
    value.addEventListener("click", function() {
      handleModal(index, modalId);
    });
  });
}

if (typeof allModals !== "undefined" && allModals !== null) {
  forEach(allModals, function(index, value) {
    // cache a nodelist of the close button inside the modal
    let button = value.querySelectorAll(".close");
    // add event listeners to each close button inside the modals
    button[0].addEventListener("click", function() {
      closeModal(value, "button close");
    });
  });
}

function handleModal(i, id) {
  // just in case, clear any other active modals
  forEach(allModals, function(index, value) {
    value.classList.remove("active");
    if (allModals[index].id === id) {
      allModals[index].classList.add("active");
    }
  });
  // add an active class to the desired modal
  // allModals[i].classList.add("active");
  // add an active class to the container as well
  modalContainer.classList.add("active");
}

function closeModal(modal, source) {
  if (source === "from button") {
    // if we're closing from a button, remove the active class from the surrounding modal
    modal.path[1].classList.remove("active");
  } else {
    // otherwise, remove the active class from the container and ...
    modalContainer.classList.remove("active");
    forEach(allModals, function(index, value) {
      // remove the active class from all modals
      modal.classList.remove("active");
    });
  }
}

              
            
!
999px

Console