dave
1/3/2018 - 9:24 PM

Standard CSS Modal

Standard CSS Modal

<a href="#" class="btn" id="modalOpen">Open Modal</a>
<div class="modal__containter">
  
  <div class="modal hide">
    <a href="#" class="modal__close"><img src="http://image.flaticon.com/icons/png/128/61/61155.png"></a>
    <div class="modal__content">
      <h3>This is a Modal</h3>
      <p>Maybe it's for a newsletter signup. Or just to say hello. It could be for whatever really..</p>
      <form>
        <input type="text" placeholder="Email">
        <button class="btn">Submit</button>
      </form>
    </div>
  </div>
</div>
.modal__containter {
  position: relative;
  &.modal__open {
    overflow: hidden;
    &:before {
      content: '';
      display: inline-block;
      background: rgba(0,0,0,0.5);
      position: fixed;
      top: -100%;
      bottom: 0;
      left: -100%;
      right: 0;
      z-index: 0;
      height: 200vh;
      width: 200vw;
    }
  }
}

.btn {
  text-decoration: none;
  color: black;
  background: white;
  text-transform: lowercase;
  font-family: helvetica;
  letter-spacing: 0.05em;
  font-size: 16px;
  padding: 10px 20px;
  display: inline-block;
  border: 3px solid black;
}

.modal {
  display: block;
  width: 500px;
  margin: 0 auto;
  text-align: center;
  border: 3px solid black;
  position: fixed;
  background: white;
  top: 60px;
  left: 0;
  right: 0;
  z-index: 1;
  -webkit-box-shadow: 3px 3px 20px 0px rgba(0,0,0,0.6);
  box-shadow: 3px 3px 20px 0px rgba(0,0,0,0.6);
  opacity: 0;
  transform: translateY(100px);
  transition: opacity 0.5s ease, transform 0.6s ease;
  &.visible {
    opacity: 1;
    transform: translateY(0); 
    transition: opacity 0.5s ease, transform 0.6s ease;
  }
  &.transition {
    opacity: 0;
    transform: translateY(100px);
    transition: opacity 0.5s ease, transform 0.6s ease;
  }
  &.hide {
    display: none;
  }
  h3,
  p {
    font-family: helvetica;
    letter-spacing: 0.05em;
  }
  h3 {
    font-size: 26px;
  }
  p {
    font-size: 14px;
    margin-bottom: 10px;
  }
  form {
    margin-top: 20px;
    input[type=text]{
      display: block;
      width: 300px;
      margin: 0 auto;
      font-family: helvetica;
      letter-spacing: 0.05em;
      font-size: 14px;
      padding: 5px 10px;
      border: 2px solid black;
      &:focus {
        outline: none;
        border: 2px solid black;
      }
    }
    button {
      cursor: pointer;
      background: white;
      outline: none;
      margin-top: 20px;
      transition: color 0.3s ease, background 0.3s ease;
      &:hover {
        background: black;
        color: white;
      }
    }
  }
}
.modal__content {
  padding: 20px 90px;
}
.modal__close{
   display: inline-block;
   position: absolute;
   top: 0;
   right: 0;
   padding: 15px;
   &:after {
     content: '';
     display: inline-block;
     height: 100%;
     width: 100%;
     position: fixed;
     top: -100%;
     bottom: 0;
     left: -100%;
     right: 0;
     height: 200vh;
     width: 200vw;
     z-index: -1;
   }
   img {
     height: auto;
     width: 20px;
   }
 }
$(document).ready(function(){
  
  $('#modalOpen').on('click', function(){
    $('.modal__containter').addClass('modal__open');
    setTimeout(function(){
      $('.modal').removeClass('hide');
      $('.modal').addClass('transition');
    });
    setTimeout(function(){
      $('.modal').removeClass('transition');
      $('.modal').addClass('visible');
      },50);
  });
  
  $('.modal__close').on('click', function(){
    $('.modal__containter').removeClass('modal__open');
    $('.modal').removeClass('visible');
    $('.modal').addClass('transition');
    setTimeout(function(){
      $('.modal').removeClass('transition');
      $('.modal').addClass('hide');
    },500);
  });
  
});

View it on Code Pen:

http://codepen.io/DinosVsRobots/pen/WRvodR