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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <nav>
  <div class="accordion accordion--accent">
    <div class="accordion__head">Cakes</div>
    <div class="accordion__sub">
      <div class="accordion__sub-item">Devil's Food</div>
      <div class="accordion__sub-item">Carrot</div>
      <div class="accordion__sub-item">Lemon</div>
    </div>
  </div>

  <div class="accordion accordion--accent">
    <div class="accordion__head">Cookies</div>
    <div class="accordion__sub">
      <div class="accordion__sub-item">Chocolate Chip</div>
      <div class="accordion__sub-item">Oatmeal</div>
      <div class="accordion__sub-item">Macaroons</div>
    </div>
  </div>

  <div class="accordion">
    <div class="accordion__head">Chocolates</div>
    <div class="accordion__sub">
      <div class="accordion__sub-item">Truffles</div>
      <div class="accordion__sub-item">Pretzels</div>
      <div class="accordion__sub-item">Turtles</div>
      <div class="accordion__sub-item">Barks</div>
      <div class="accordion__sub-item">Brownies</div>
    </div>
  </div>

  <div class="accordion">
    <div class="accordion__head">Pies</div>
    <div class="accordion__sub">
      <div class="accordion__sub-item">Coconut Cream</div>
      <div class="accordion__sub-item">Blueberry Peach</div>
      <div class="accordion__sub-item">Lemon Meringue</div>
    </div>
  </div>
  <div class="accordion accordion--hr">
    <div class="accordion__head">How to Bake</div>
    <div class="accordion__sub">
      <div class="accordion__sub-item">Mixing</div>
      <div class="accordion__sub-item">Measuring</div>
      <div class="accordion__sub-item">Frosting</div>
    </div>
  </div>
</nav>
            
          
!

CSS

            
              $c-main: #00A896;
$c-hover: #f3f3f3;
$c-text: #333;
$c-bg-accent: lighten($c-main, 58%);
$c-bg-page: lighten($c-main, 70%);
$c-border: $c-main;
$c-hr: lighten($c-main, 58%);

body {
  font-family: Georgia;
  font-size: 1rem;
  color: $c-text;
  background-color: $c-bg-page;
// these two lines of code are a codepen thing
  margin: 0;
  padding: 0;
}

nav {
  border-right: .15rem solid $c-hr;
  width: 20rem;
  height: 100vh;
  padding: 0;
  box-sizing: border-box;
}

.accordion{
  width: 20rem;
  &--accent {
    background-color: $c-bg-accent;
  }

  &--hr {
    border-top: 0.15rem solid $c-hr;
  }
}
.accordion__head {
  font-weight: 700;
  cursor: pointer;
  padding: 1rem;
  transition: all 500ms ease;
  border-left: 0.35rem solid transparent;
  
  &.active, &:hover {
    border-left: 0.35rem solid $c-border;
  }
}

.accordion__sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height 400ms ease-out;
  padding-bottom: 0.5rem;
}

.accordion__sub-item {
  padding: 0.25rem;
  padding-left: 2rem;
  margin: 0.5rem 0; 
  border-left: 0.35rem solid transparent;
  &.active, &:hover {
      border-left: 0.35rem solid $c-border;
      background-color: $c-hover;
  }
}

            
          
!

JS

            
              const accordion = Array.from(document.getElementsByClassName('accordion__head'));

accordion.forEach((el) => {
  const element = el;
  element.onclick = (e) => {
    const subNav = e.target.nextElementSibling;
    e.target.classList.toggle('active');

    if (subNav.style.maxHeight) {
      subNav.style.maxHeight = null;
    } else {
      subNav.style.maxHeight = `${subNav.scrollHeight}px`;
    }
  };
});

            
          
!
999px

Console