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

              
                <div id="contents">
  <h1>Garden of Contents</h1>
  <p>Welcome to the fabled garden, where you'll hopefully be able to find a flower suitable to your liking!</p>

  <!-- These nested unordered lists are the Table of Contents itself. -->

  <ul>

    <!-- below is an important part - the link at the very top of the index that toggles opening and closing all sections of the index at once. you can change the text it displays below -->

    <li id="unfolder"><span id="uneclipse">Unfold all sections...</span><span id="uneclipsed" class="hidden">Hide all sections...</span></li>
    <li><a href="#" name="Roses">Roses</a></li>

    <!-- Lacking an href, they're clickable titles for nested sections within the table itself, ie, this one. To do this, you're going to want to apply that class (.eclipse) to the title of every nested part of list, as shown below -->

    <li><a class="eclipse">Seasonal Blooms</a>
      <ul>
        <li><a href="#">Perpetual Flowerings</a></li>

        <!-- As you can see below, applying the class .gray to any ul or li (nested or not) will gray it out and add a null symbol (configurable in the CSS) to indicate that it is unfinished -->

        <li class="gray"><a class="eclipse">Hazards and Joys</a>

          <!-- As you'll notice here, you can comfortably have a table of contents nested three levels deep. If you edit the CSS yourself, you can probably make it work for four levels or so, if absolutely necessary. -->

          <ul>
            <li><a href="#">Beagles and Digging</a></li>
            <li><a href="#">Birds and Stuff</a></li>
          </ul>
        </li>

        <!-- Here are some more examples of both nested, unnested, and grayed-out links -->

        <li><a href="#">Spring</a></li>
        <li><a href="#">Summer</a></li>
        <li><a href="#">Autumn</a></li>
        <li class="gray"><a href="#">Winter</a></li>
      </ul>
    </li>
    <li class="gray"><a href="#">Growing Herbs</a></li>
    <li><a href="#">Pollinators</a></li>
    <li><a class="eclipse">Exotic Flowers</a>
      <ul>
        <li><a href="#">What are exotic flowers?</a></li>
        <li><a href="#">Orchids</a></li>
        <li><a href="#">Lotus</a></li>
      </ul>
    </li>
    <li><a class="eclipse">Wildflowers</a>
      <ul>
        <li><a href="#">Why wildflowers?</a></li>
        <li><a href="#">Daisies</a></li>
        <li><a href="#">Dandelion</a></li>
      </ul>
    </li>
    <li class="gray"><a href="#">Lawncare</a></li>
  </ul>
</div>

<!-- we here have jquery, which MUST BE INCLUDED in order for this to work, but it really ought go at the bottom of your site -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
              
            
!

CSS

              
                /* this is a fancified demonstrative version of the CSS. all colors, text, etc, is for demonstration purposes only and can be changed - that is, of course, precisely the point. */
body {
  background-color: #f8c8c8;
}
/* we begin styling of the box which contains the table of contents. here, it's just in the middle of the page, and called "#contents," but could easily be renamed or removed, since it serves primarily an aesthetic function here, as does everything else between this and the unordered list styling itself */
#contents {
  width: 40%;
  background-color: white;
  font-family: Helvetica;
  margin: auto;
  padding: 0 0 1.5em;
  color: #400;
  border: 1px dashed #f8c8c8;
}

#contents p {
  padding: 1em;
  text-align: justify;
  margin: 0px;
}

/* a little fancy title, nothing more, dearies */
#contents h1 {
  color: #ffffff;
  background: #b35a60;
  padding: 0.4em;
  margin-bottom: 0px;
  font-size: 4em;
  font-variant: small-caps;
  font-style: oblique;
  font-family: impact;
  letter-spacing: 0.1em;
  line-height: 0.7em;
  text-align: center;
  margin-top: 0px;
  text-shadow: 4px 3px 10px #8f484c;
}

/* and the chaos of unordered lists begins, which will allow, ultimately, for a pleasing appearance to the form itself. we shall begin with this tidbit, which makes sure that the menu is collapsed when it loads and that the interior sections don't initially display */

#unfolder {
  font-weight: bold;
  text-decoration: underline;
  cursor: pointer;
} /* this particular portion styles the initial link to open the index completely */
.hidden {
  display: none;
}
.shown {
  display: visible;
}

.eclipse + ul {
  display: none;
}

/*the below part is important, though, because it provides feedback to the user - lets 'em know they can click on certain parts to see more. */
.eclipse {
  cursor: pointer;
}

/* below organizes colors, padding, margins, etc, for the nested unordered lists within the table of contents. you can play with these a bit to  */
#contents ul {
  margin: 1em;
  width: 84%;
  margin: auto;
  margin-top: 0em;
  margin-bottom: 0em;
}
#contents ul ul li,
#contents ul ul ul li {
  border: 0px;
}
#contents ul,
#contents ul ul,
#contents ul ul ul {
  color: #b35a60;
  padding-left: 0em;
  padding-top: 0.4em;
  padding-bottom: 0em;
}

/* the entry for list-style-type below will be the symbol to the left of top-level items */
#contents ul li {
  list-style-type: "❁";
  padding: 0.5em;
  border-bottom: 1px dashed #f8c8c8;
  text-align: left;
}

#contents ul li:last-child {
  border-bottom: 0;
}

/* below, list-style-type designates the symbol of second-level items */
#contents ul ul li {
  list-style-type: "➺";
}

/* and below, you can change the symbol for third-level items */
#contents ul ul ul li {
  list-style-type: "❀";
}

/* i'm here going to style the links a bit, including their color, whether they're underlined, and a nice background color on hover; you can remove this if you want your theme to supersede it */

#contents li a {
  color: #b35a60;
  text-decoration: underline;
}

#contents li a:hover {
  background-color: #f8c8c8;
  color: #b35a60;
  transition: 1s;
}
/* this part creates the .gray class, which you add to any list item (or an entire nested list) to turn it gray and demonstrate that it isn't finished. */

#contents .gray a {
  color: #e3bec7;
  text-decoration: none;
}

#contents .gray * {
  color: #e3bec7;
}

#contents .gray a::before {
  content: "∅";
  font-weight: bold;
  color: #e3bec7;
  margin-right: 0.3em;
  color: "#E3BEC7";
}

              
            
!

JS

              
                //THIS PORTION WILL CONTROL THE SPEED AT WHICH YOUR MENU EXPANDS AND CONTRACTS WHEN SINGLE SECTIONS ARE OPENED, USING THE JQUERY SLIDETOGGLE SPELL. I JUST SET IT TO "SLOW," BUT IT CAN BE LISTED IN SECONDS (IE, 1S), OR MILLISECONDS, (IE 300MS).DITTO FOR THE SPEED OF SLIDEUP AND SLIDEDOWN USED BELOW, TOO.

$(document).ready(function () {
  $(".eclipse").click(function () {
    $(this).next("ul").slideToggle("slow");
  });

  var concealed = $(".eclipse");
  var revealed = false;

  //THE #UNFOLDER IS THE ELEMENT THAT ONE CLICKS TO... UNFOLD EVERYTHING. I APPLIED IT TO THE FIRST LIST ITEM...

  $("#unfolder").click(function (event) {
    event.preventDefault();
    if (revealed) {
      concealed.each(function () {
        $(this).next("ul").slideUp("slow");
      });

      //#UNECLIPSE AND #UNECLIPSED ARE IDS APPLIED TO SPAN TAGS THAT APPEAR WITHIN #UNFOLDER DEPENDING ON WHETHER THE TABLE IS HIDDEN OR UNFOLDED, RESPECTIVELY. THIS LETS YOU TELL THE USER WHERE TO CLICK TO TOGGLE. CONTENTS OF THESE TAGS CAN BE CHANGED WITHIN THE HTML...

      $("#uneclipse").removeClass("hidden").addClass("shown");
      $("#uneclipsed").removeClass("shown").addClass("hidden");
      revealed = false;
    } else {
      concealed.each(function () {
        $(this).next("ul").slideDown("slow");
      });
      $("#uneclipsed").removeClass("hidden").addClass("shown");
      $("#uneclipse").removeClass("shown").addClass("hidden");
      revealed = true;
    }
  });
});

              
            
!
999px

Console