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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="btn__container">
  <h1>CSS Only Modals</h1>
  <label for="modal__one" class="btn btn--1">Launch Modal</label>
  <a href="#modal-two" class="btn btn--2">Launch Modal 2</a>
</div>
 
<section class="modal__container">
  
  <!-- Modal 1 -->
  <input type="checkbox" id="modal__one" class="modal__state">   
  <div class="modal">
    <label for="modal__one" class="modal__overlay"></label>
    <div class="modal__inner">
      <label for="modal__one" class="btn modal__close"></label>
      <h2>Modal 1 Inner</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas provident vitae accusamus est non, excepturi soluta laboriosam totam at tenetur rem incidunt sed, nulla sequi laborum et temporibus, saepe maxime.</p>
    </div>
  </div>
  
  <!-- Modal 2 -->
  <div id="modal-two">
    <a href="#" class="modal-two__overlay"></a>
    <div class="modal-two__inner">
      <a href="#" class="btn modal__close"></a>
      <h2>Modal 2 Inner</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque alias at soluta veritatis explicabo adipisci excepturi quis magnam officia in.</p>
    </div>
  </div>
</section>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Montserrat');
$btn-color--1: #60C6C7;
$btn-color--2: #CD5874;
$btn-color--3: #C53E2C;

*, *::before, *::after {
  box-sizing: border-box;
}
html, body {
  height: 100%;
}
html {
  font-size: 100%;
}
body {
  margin: 0;
  padding: 0;
  font: {
    size: 1rem;
    family: 'Montserrat', Arial;
  }
  background-color: #e3e3e3;
  line-height: 1.4;
}
h1 {
  font-size: 2.4rem;
  margin: 0 0 1em 0;
}
a {
  text-decoration: none;
}

/**
* Modal 1 Styles
*/
.modal {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease-out;

  &__overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    cursor: pointer;
    background-color: rgba(0,0,0,0.4);
  }
  
  &__state {
    display: none;
    
    &:checked + .modal {
      opacity: 1;
      visibility: visible;
      
      .modal__inner {
        transform: translate(-50%, -50%); 
      }
    }
  }
  
  &__inner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -75%);
    width: 50%;
    height: 50%;
    margin: auto;
    padding: 1em 1.4em;
    overflow: auto;
    background-color: #fff;
    border-radius: .3em;
    box-shadow: 0 3px 12px rgba(0,0,0,0.8);
    transition: transform .3s ease-out;
    
    h2 {
      margin: 0;
      text-shadow: 0px 1px 2px rgba(0,0,0,0.2);
    }
  }
}

/**
* Modal 2 Styles
*/
#modal-two {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  opacity: 0;
  transform: opacity 1s ease-out;
  
  &:target {
    pointer-events: all;
    opacity: 1;
    
    .modal-two__inner {
      transform: translate(-50%, -50%);
      opacity: 1;
    }
  }
  
  .modal-two__overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    cursor: pointer;
    background-color: rgba(0,0,0,0.4);
  }
  
  .modal-two__inner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -25%);
    width: 50%;
    height: 50%;
    margin: auto;
    padding: 1em 1.4em;
    overflow: auto;
    background-color: #fff;
    opacity: 0;
    border-radius: .3em;
    box-shadow: 0 3px 12px rgba(0,0,0,0.8);
    transition: all .3s ease-out;
    
    h2 {
      margin: 0;
    }
  }
}
/**
* Extras
*/ 
.btn__container {
  width: 80%;
  margin: 0 auto;
  padding: 2em 1.5em;
  text-align: center;
}
.btn {
  padding: .625em .75em;
  border-radius: 3px;
  color: #fff;
  cursor: pointer;
  display: inline-block;
  transform: translateY(0);
  transition: transform 0.2s ease;
} 
.btn--1 {
  background-color: $btn-color--1;
  box-shadow: 0 4px 0 darken($btn-color--1, 8%);
  
  &:hover, &:focus {
    background-color: lighten($btn-color--1, 8%);
    box-shadow: 0 4px 0 $btn-color--1;
  }
  &:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 $btn-color--1;
  }
}
.btn--2 {
  background-color: $btn-color--2;
  box-shadow: 0 4px 0 darken($btn-color--2, 6%);
  
  &:hover, &:focus {
    background-color: lighten($btn-color--2, 6%);
    box-shadow: 0 4px 0 $btn-color--2;
  }
  &:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 $btn-color--2;
  }
}

.modal__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  background-color: $btn-color--3;
  box-shadow: 0 4px 0 darken($btn-color--3, 10%);
  
  &:hover, &:focus {
    background-color: lighten($btn-color--3, 6%);
    box-shadow: 0 4px 0 $btn-color--3;
  }
  &:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 $btn-color--3;
  }
  
  &::before,
  &::after {
    content: '';
    position: absolute;
    width: 3px;
    height: 16px;
    background-color: #fff;
    left: 50%;
    top: 0;
    margin: 7px 0 0 -1px;
    transform: rotate(45deg);
  }
  &::after {
    transform: rotate(-45deg);
  }
}

@media screen and (max-width: 768px) {
  .modal__inner,
  .modal-two__inner {
    width: 90%;
    height: 85%;
  }
}
              
            
!

JS

              
                /**
* Here are two CSS Modals that use 
* different methods to trigger their open state
* One with labels/checkboxes.
* The other with the :target selector
*/ 
              
            
!
999px

Console