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.

            
              <h1 class="page-header">Problem: Create a modal</h1>
<blockquote>
In the last part of the interview I ask the candidates to build something practical, usually an 'overlay' library. I find this useful, as it demonstrates a full front-end stack: HTML, CSS and JavaScript. If a candidate excels at the previous part of the interview, I move to this question as soon as possible.
</blockquote>

<button type="button" id="modal-trigger" class="btn btn-default">Show Model</button>

<div class="sb-modal" id="modal">
  <div class="sb-modal-body">
    <header>
      <h3>My Dialog</h3>
    </header>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis ea, fugit nemo maxime voluptates ab ex labore quasi corporis quos doloremque assumenda libero officiis explicabo non? Quis reprehenderit excepturi, adipisci!
    </p>
  </div>
</div>


<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam fugit eos mollitia nihil doloribus voluptatibus, nulla repudiandae ipsa officia cumque quisquam explicabo aliquid illum laborum. Architecto ipsum, laborum perspiciatis ullam.</p>
            
          
!
            
              .sb-modal, .sb-modal-body {
  display: none;
  position: fixed;
  
}

.sb-modal {
  background-color: rgba(0, 0, 0, 0.8);
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  
  &.open {
    display: block;
  }
}
.sb-modal-body {
  top: 10%;
  bottom: 10%;
  right: 10%;
  left: 10%;
  @media screen and (min-width: 500px) {
    top: 50%;
    bottom: 50%;
    margin-top: -25%;
    margin-bottom: -25%;
    width: 50%;
    right: 25%;
    left: 25%; 
  }
  
  background: #FFFFFF;
  border: 1px solid #333333;
  border-radius: 3px;
  padding: 20px;
  .open &{
    display: block;
  }
  &:before {
    display: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
}

            
          
!
            
              



function initModal (trigger, target) {
  trigger.addEventListener('click', function () {
    modal.classList.add('open');
    document.body.classList.add('modal-open');
    target.addEventListener('click', function (ev) {
      if (ev.target === ev.currentTarget) {
        target.classList.remove('open');
        document.body.classList.remove('modal-open');
      }
   });
  });
}

var trigger = document.getElementById('modal-trigger');
var modal = document.getElementById('modal')

initModal(trigger, modal);
            
          
!
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