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

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="notice" data-bind="visible: notifications().length > 0">
  <ul data-bind="foreach: notifications">
    <li class="message">
      <span data-bind="text: message"></span>  
      <a href="#" data-bind="click: $parent.removeNotification" class="close">&times;</a>
    </li>    
  </ul>
</div>

<a href="#" class="trigger">Trigger message</a>
              
            
!

CSS

              
                @import "bourbon";

html {
  background: #fff;  
  font-family: sans-serif;
}

.notice {
  position: fixed;
  left: 1em;
  right: 1em;
  box-sizing: border-box;
  padding: 1em;
  background: #fff;
  box-shadow: 0px 5px 15px rgba(0, 0, 0, .25);
  
  ul, li {
    margin: 0;
    padding: 0;
    list-style-type: none;
  }
  
  li {
    position: relative;
    margin-bottom: .5em;
    &:last-of-type {
      margin-bottom: none;
    }
  }
  
  .close {
    position: absolute;
    top: 0;
    right: 0;
    text-decoration: none;
    background: #aaa;
    color: #fff;
    display: inline-block;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
    border-radius: 50%;
    font-weight: 100;
    font-size: 12px;
    @include transition(background 100ms);
    &:hover {
      background: #a00;
    }
  }
}

a.trigger {
  @include button();
  position: absolute; 
  bottom: 1em;
  text-align: center;
  left: 50%;
  width: 200px;
  margin-left: -100px;
}
              
            
!

JS

              
                // Create knockout model:
function NotificationModel() 
{
  var self = this;
	
  // Create an observable array for the notifications:
  self.notifications = ko.observableArray([]);
  
  // Create a function to add the notification:
  self.addNotification = function(notification)
  {
    self.notifications.push(
      {
    	  'message' : notification
      }
    );
  };
  
  // Create a function to remove the notification:
  self.removeNotification = function()
  {
    self.notifications.remove(this);
  }
};

// Entry point:
document.addEventListener('DOMContentLoaded', function(){
  // Apply bindings:
  var notifications = new NotificationModel();
	ko.applyBindings(notifications);
  document.querySelector('.trigger').addEventListener('click', function(e){
    e.preventDefault();
    notifications.addNotification(
      'Hello world!');
  });
});
              
            
!
999px

Console