Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <ul>
  <li><a href="#">
    <img src="https://image.flaticon.com/icons/svg/263/263115.svg" width="20" height="20" alt=""><span>Home</span></a></li>
  <li class="selected"><a class="toggle" href="#example"><img src="https://image.flaticon.com/icons/svg/263/263078.svg" width="20" height="20" alt=""><span>Billing</span><img src="https://image.flaticon.com/icons/svg/566/566015.svg" width="12" height="12" alt="" class="chevron">
    </a>
    <div class="toggle-content" id="example">
      <ul>
        <li><a href="#">Monthly Bill</a></li>
        <li><a href="#">Pay History</a></li>
      </ul>
    </div>
  </li>
  <li><a href="#">
    <img src="https://image.flaticon.com/icons/svg/263/263058.svg" width="20" height="20" alt=""><span>Employees</span></a></li>
  <li><a href="#"><img src="https://image.flaticon.com/icons/svg/263/263146.svg" width="20" height="20" alt=""><span>Claims</span></a></li>
  <li><a href="#"><img src="https://image.flaticon.com/icons/svg/263/263122.svg" width="20" height="20" alt=""><span>Docs</span></a></li>
</ul>
            
          
!
            
              .toggle {
  border-left: 5px solid #015295;
  padding-left: calc(1.5rem - 5px);
}

.toggle-content {
  display: none;
  height: 0;
  overflow: hidden;
  transition: height .3s ease-in-out;
}

.toggle-content.is-visible {
  display: block;
  height: auto;
}











/* general styling */
ul {
  font-family: sans-serif;
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 250px;
}

li {
  color: #404040;
  font-size: 0.75rem;
  letter-spacing: -0.4px;
  text-transform: uppercase;
}

.selected {
  background-color: #f2f6f9;
}

li ul {
  margin-left: calc(1.5rem + .75rem);
  padding: 0;  
}

li img {
  margin-right: 1rem;
}

li a {
  color: inherit;
  display: block;
  padding: 1.15rem 1.5rem 1.15rem;
  text-decoration: none;
}

li a:hover {
  background-color: #f2f6f9;
}

li span {
  position: relative;
  top: -.25rem;
}

li li {
  background-color: transparent;
  text-transform: initial;
}

.chevron {
  float: right;
  margin: .35rem 0 0 0;
}

@media only screen and (max-width: 700px) {
  ul {
    width: 100%;
  }
  
  li {
    font-size: 1rem;
  }
}
            
          
!
            
              // Show an element
var show = function (elem) {

  // Get the natural height of the element
  var getHeight = function () {
    elem.style.display = 'block'; // Make it visible
    var height = elem.scrollHeight + 'px'; // Get it's height
    elem.style.display = ''; //  Hide it again
    return height;
  };

  var height = getHeight(); // Get the natural height
  elem.classList.add('is-visible'); // Make the element visible
  elem.style.height = height; // Update the max-height

  // Once the transition is complete, remove the inline max-height so the content can scale responsively
  window.setTimeout(function () {
    elem.style.height = '';
  }, 350);

};

// Hide an element
var hide = function (elem) {

  // Give the element a height to change from
  elem.style.height = elem.scrollHeight + 'px';

  // Set the height back to 0
  window.setTimeout(function () {
    elem.style.height = '0';
    console.log('window.setTimeout');
  }, 1);

  // When the transition is complete, hide it
  window.setTimeout(function () {
    elem.classList.remove('is-visible');
    console.log('window.setTimeout:remove is-visible');
  }, 300);

};

// Toggle element visibility
var toggle = function (elem, timing) {

  // If the element is visible, hide it
  if (elem.classList.contains('is-visible')) {
    hide(elem);
    return;
    console.log('hide element');
  }

  // Otherwise, show it
  show(elem);
  console.log('show element');

};

// Listen for click events
document.addEventListener('click', function (event) {

  
  // Make sure clicked element is our toggle
  if (!event.target.closest('a').classList.contains('toggle')) {
    return;
  }

  // Prevent default link behavior
  event.preventDefault();

  // Get the content
  console.log(event.target.closest('a').hash);
  var content = document.querySelector(event.target.closest('a').hash);
  if (!content) return;

  // Toggle the content
  toggle(content);

}, false);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console