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

              
                button.btn.btn-primary.js-modal-trigger(type="button" data-target="#myModal") test modal

button.btn.btn-success.js-alert-trigger(type="button") test alert

.alert-dismissable-group
  .alert.alert-success.alert-dismissable.js-alert
    p this is the alert yo
    button.close.btn.btn-close.js-force-close <span>&times;</span>


<!-- Modal -->
#myModal.modal.fade.js-modal(tabindex="-1" role="dialog" aria-labelledby="myModalLabel")
  .modal-dialog(role="document")
    .modal-content
      .modal-header
        button.close(type="button" data-dismiss="modal" aria-label="Close") <span aria-hidden="true">&times;</span>
        h4#myModalLabel.modal-titleModal title
      .modal-body ...
      .modal-footer
        button.btn.btn-default(type="button" data-dismiss="modal") Close
        button.btn.btn-primary(type="button") Save changes

              
            
!

CSS

              
                
.alert {
  padding-right: 40px;
  
  .close {
    padding: 10px;
    position: absolute;
    right: 0;
    top: 0;
  }
}

.alert-dismissable-group {
  bottom: 15px;
  left: 15px;
  position: fixed;
}

.alert-dismissable {
  opacity: 0;
  transform: translateY(100%);
  transition: opacity .3s ease-out, transform .01s linear .3s;
  
  &.is-shown {
    opacity: 1;
    transform: translateY(0);
    transition: all .3s ease-out;
  }
}


body {
  min-height: 100vh;
  padding: 2rem;
}


* {
  &, &:before, &:after {
    box-sizing: border-box;
    &, &:focus, &:active, &:focus:active {
      outline: none;
    }
  }
}

              
            
!

JS

              
                
var autoCloseTimeout;

$('.js-alert').on('click', '.js-force-close', function(e) {
  $(this).parents('.alert').removeClass('is-shown');
  clearTimeout(autoCloseTimeout);
});

// modal example
$('.js-modal-trigger').on('click', function(e) {
  e.preventDefault();
  autoClose({
    target: $('.js-modal'),
    timeout: 2000
  });
});

// alert example
$('.js-alert-trigger').on('click', function(e) {
  e.preventDefault();
  autoClose({
    contextual: 'danger',
    target: $('.js-alert'),
    timeout: 2000
  });
});

/*
* Function to auto close alerts and modals
* Available Options:
*   target(required) [object] - the element to be triggered with an auto close timeout
*   timeout [number] - the number of milliseconds to keep the element open before closing
*   contextual [string] - for alerts, the contextual name to apply to the alert (success, danger, info, warning)
* Note: if content is updated via JS, it must be done prior to calling this function
*/
function autoClose(options) { // eslint-disable-line
  // set defaults
  const defaults = {
    contextual: 'success',
    timeout: 4000
  };
  // apply options
  const $obj = options.target;
  const contextual = options.contextual || defaults.contextual;
  const timeout = options.timeout || defaults.timeout;
  let type = 'modal';

  if ($obj.hasClass('alert')) {
    type = 'alert';
    $obj.removeClass('alert-danger alert-info alert-success alert-warning').addClass('alert-' + contextual);
  }

  // trigger modal or show alert
  type === 'modal' ? $obj.modal('show') : $obj.addClass('is-shown');

  clearTimeout(autoCloseTimeout); // eslint-disable-line

  autoCloseTimeout = setTimeout(function() { // eslint-disable-line
    type === 'modal' ? $obj.modal('hide') : $obj.removeClass('is-shown');
  }, timeout);
}
              
            
!
999px

Console