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

              
                
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Montserrat:400,700|Lato);
@import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css);

body > button{
  display:block;
  margin:24px auto;
  padding:12px 18px;
  font-family:Montserrat;
  border:0;
  border-radius:3px;
  box-shadow:0 2px 12px 0 rgba(50,50,50,.2);
  cursor:pointer;
  transform:scale(1);
  transition:.218s ease;
}

body > button:hover{
  transform:scale(1.2);
}

#overlay{
  font-family:Lato;
  position:fixed;
  width:100vw;
  height:100vh;
  overflow:hidden;
  top:0;
  left:0;
  right:0;
  bottom:0;
  animation:modal .2s forwards ease;
  background-color:rgba(0,0,0,.8);
  transform:scale(1);
  transform-origin:center center;
}

@keyframes modal{
  from{
    background-color:rgba(0,0,0,0);
    transform:scale(3);
  };
  to{
    background-color:rgba(0,0,0,.8);
    transform:scale(1);
  }
}

#overlay > div{
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  max-width:400px;
  width:90%;
}

#modal{
  background-color:#e0e0e0;
  border-radius:3px;
  overflow:hidden;
  -webkit-box-shadow: 0px 2px 16px 2px rgba(0,0,0,0.5);
-moz-box-shadow: 0px 2px 16px 2px rgba(0,0,0,0.5);
box-shadow: 0px 2px 16px 2px rgba(0,0,0,0.5);
}

#modal > div{
  padding:1em;
  color:#424242;
  background-color:#eee;
}

#modal > div *{
  max-width:100%;
}

#overlay header{
  font-family:Montserrat;
  font-size:1.2em;
  padding:.5em;
  
}

#overlay header:before{
  font-family:fontawesome;
  margin-right:1ex;
}

#notify, #overlay .notify{
  background-color:#ffa000;
  color:#fff;
}

#overlay .notify:before{
  content:"\f024";
}

#error, #overlay .error{
  background-color:#e91e63;
  color:#fff;
}

#overlay .error:before{
  content:"\f071";
}

#wait, #overlay .wait{
  background-color:#5677fc;
  color:#fff;
}

#overlay .wait:before{
  content:"\f254";
}

#success, #overlay .success{
  background-color:#42bd41;
  color:#fff;
}

#overlay .success:before{
  content:"\f058";
}

#confirm{
  background-color:#009688;
  color:#fff;
}

#custom{
  background-color:#9c27b0;
  color:#fff;
}

#overlay footer{
  text-align:right;
  padding-top:.5em;
}

#overlay footer button{
  margin-left:.5em;
  padding:.5em .8em;
  border:0;
  cursor:pointer;
  color:#fff;
  border-radius:3px;
  font-family:Montserrat;
  font-size:1.1em;
}

#overlay footer button:focus{
  outline:0;
}

#modalCancel{
  background-color:transparent;
}

#modalConfirm{
  background-color:#5677fc;
}

#modal input,
#modal select{
  border: 1px solid #bdbdbd;
  padding: .3em;
  border-radius: 3px;
  font-size: 1.1em;
  color: #424242;
  font-family: Lato;
}
              
            
!

JS

              
                var buttons = ['notify', 'error', 'wait', 'confirm', 'success', 'custom'];
for(var i = 0; i < buttons.length; i++){
  var button = buttons[i];
  var btn = document.createElement('button');
  btn.innerText = 'Show ' + button + ' modal';
  btn.id = button;
  document.body.appendChild(btn);
  addHandler(btn, button);
};

function addHandler(el, type){
  el.addEventListener('click', function(){
    var opts = {
      type : type,
      content : 'Showing this great ' + type + ' modal'
    };
    
    if(type === 'custom'){
      var input = buildComponent('input', 'name');
      input.type = 'text';
      opts.content = input;
      opts.reject = function(){
        return input.value === '';
      };
      opts.confirmAction = function(){
        console.log(input.value);
      };
    };
    
    var modal = modalBox(opts);
    if(type === 'wait'){
      var t = setTimeout(function(){
        modal.destroy();
        clearTimeout();
      }, 2000)
    };
    
  });
}

function modalBox(args){
  //set defaults
  var types = ['notify', 'error', 'wait', 'confirm', 'success', 'custom'];
  var headlines = ['Alert', 'Error', 'Please Wait', 'Please Confirm', 'Success', 'Prompt'];
  
  var options = {
    type : 'notify', 
    headline : '',
    content : '',
    cancelText : 'Cancel',
    confirmText : 'OK',
    cancelAction : function(){},
    confirmAction : function(){},
    reject : false,
  };
  
  //set the options
  if(args) for(arg in args) options[arg] = args[arg];
  
  //overrides
  if(types.indexOf(options.type) < 0) options.type = 'notify';
  if(options.headline === '') options.headline = headlines[types.indexOf(options.type)];
  if(options.type === 'success' || options.type === 'error') options.cancelText = '';
  if(options.type === 'wait'){
    options.cancelText = '';
    options.confirmText = '';
  };
  
  //build the modal
  var overlay = buildComponent('div', 'overlay');
  var outermodal = buildComponent('div');
  var innermodal = buildComponent('div', 'modal');
  var headline = buildComponent('header', false, options.headline);
  var content = buildComponent('div', false, options.content);
  var actions = buildComponent('footer');
  headline.className = options.type;
  innermodal.appendChild(headline);
  innermodal.appendChild(content);
  
  overlay.appendChild(outermodal);
  outermodal.appendChild(innermodal); //innermodal includes headline & content
  outermodal.appendChild(actions); //actions includes action buttons
  document.body.appendChild(overlay);
  
  overlay.destroy = function(){
    if(overlay.parentNode === document.body) document.body.removeChild(overlay);
  }

  var cancel = buildComponent('button', 'modalCancel', options.cancelText);
  var confirm = buildComponent('button', 'modalConfirm', options.confirmText);
  
  if(options.cancelText !== '') actions.appendChild(cancel);
  if(options.confirmText !== '') actions.appendChild(confirm);
  
  //add event handlers
  overlay.addEventListener('click', function(e){
    if(e.target === overlay){
      options.cancelAction();
      overlay.destroy();
    }
  });
  
  cancel.addEventListener('click', function(e){
    options.cancelAction();
    overlay.destroy();
  });
  
  confirm.addEventListener('click', function(e){
    //validate; to reject return bool true or string
    var rejected = typeof options.reject === 'function' ? options.reject() : options.reject;
    if(rejected){
      var message = typeof rejected === 'string' ? rejected : 'Please complete before continuing.';
      var retry = buildComponent('p', false, message);
      content.appendChild(retry);
    } else {
      options.confirmAction();
      overlay.destroy();
    }
  });
  
  return overlay;
};

function buildComponent(tag, id, html){
  var el = document.createElement(tag.toUpperCase());
  if(id) el.id = id;
  if(typeof html === 'string') el.innerHTML = html;
  if(typeof html === 'object') el.appendChild(html);
  return el;
};

              
            
!
999px

Console