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 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

              
                <!-- Done: Change MQs to ems as that is what menu width/height is based -->
<!-- Done: MQs for tiny displays -->
<!-- Done: MQs for Windows High Contrast Mode -->
<!-- Done: Debug IE menu jumpiness -->
<!-- To-do: Test keyboard nav script -->
<!-- To-do: Browser testing -->
<!-- To-do: Screen reader testing -->
<!-- To-do: Mobile/touch testing -->
<!-- To-do: Standard fly-outs for larger displays -->
<!-- To-do: MQs for desktop display -->
<!-- To-do: Add a 'Home' link for display on smallest screens (that don't get radial menu) -->

<nav role="navigation" tabindex="0" aria-labelledby="NavLbl">
  <h1 id="NavLbl">Menu</h1>
  <ol>
    <li><a href="#Bio">Bio</a>
      <ol>
        <li><a href="#Bio1">Bio One</a></li>
        <li><a href="#Bio2">Bio Two</a></li>
        <li><a href="#Bio3">Bio Three</a></li>
      </ol>
    </li>
    <li><a href="#Blog">Blog</a></li>
    <li><a href="#Books">Books</a>
      <ol>
        <li><a href="#Books1">Book Title 1</a></li>
        <li><a href="#Books2">Second Book Title</a></li>
        <li><a href="#Books3" aria-label="Current Page: The Third Book Title">The Third Book Title</a></li>
        <li><a href="#Books4">I wrote a Fourth Book</a></li>
        <li><a href="#Books5">Five Fricking Books</a></li>
        <li><a href="#Books6">I Did Not Write A Sixth Book</a></li>
      </ol>
    </li>
    <li><a href="#Articles">Articles</a>
      <ol>
        <li><a href="#Archive1">Archive</a></li>
        <li><a href="#Archive2">Archive</a></li>
        <li><a href="#Archive3">Archive</a></li>
        <li><a href="#Archive4">Archive</a></li>
        <li><a href="#Archive5">Archive</a></li>
        <li><a href="#Archive6">Archive</a></li>
        <li><a href="#Archive7">Archive</a></li>
        <li><a href="#Archive8">Archive 8</a></li>
        <li><a href="#Archive9">Archive 9</a></li>
      </ol>
    </li>
    <li><a href="#Contact">Contact</a>
      <ol>
        <li><a href="#Contact1">Phone</a></li>
        <li><a href="#Contact2">Email</a></li>
        <li><a href="#Contact3">Stalk</a></li>
        <li><a href="#Contact4">Twitter</a></li>
        <li><a href="#Contact5">Tumblr</a></li>
        <li><a href="#Contact6">Car</a></li>
      </ol>
    </li>
    <li><a href="#Fake6">Fake 6th Item</a></li>
   </ol>
</nav>

<main>
  <h1>Radial (Sub-)Menu Experiment</h1>
  <p>
    New, Improved and Chocolatey!
  </p>
  <p>
    I have taken my first two radial menu samples (<a href="https://codepen.io/aardrian/pen/vFKuq">the first cut</a> and the <a href="https://codepen.io/aardrian/pen/HjwLr">second cut with a sub-menu</a>) and re-written them from scratch. Mostly to play around, partly to compare code from two-and-a-half years ago and see how my approach has changed. I also wrote a <a href="http://blog.adrianroselli.com/2012/08/css-only-radial-menu-experiments.html">blog post</a> some time ago (August 2012) outlining what I built before.
  </p>
  <p>
    All sizing is based on ems, so if you kick up the default font size (on the <code>body</code>) you'll see the menu, text, borders, etc. scale.
  </p>
  <p>
    I use <code>aria-label</code> to identify which item is the current page/section, using a CSS attribute selector to style accordingly (<em>Books</em> &gt; <em>The Third Book</em>). I use jQuery to walk up the DOM to find the parent anchor, which assumes I would be stuck on a CMS that won't allow this to be done server-side (which would be lame). I'm still not sold on using an <code>h1</code> in the <code>nav</code>, but at least I use <code>aria-labelledby</code> to essentially make it a label for the entire thing. 
  </p>
  <p>
    I have added keyboard support with some jQuery, though I'd like to re-write to vanilla JS so there are no external dependencies. Without scripting it doesn't work as I rely on hover/focus states on the <code>li</code> elements. I also need to test it more on touch displays.
  </p>
  <p>
    This is nowhere near ready for production. I have a media query that kills this above a certain width (set high for now) as I expect to have more traditional styles for desktop. Have added em-based height &amp; media queries to convert to block nav for smaller screens where menu options won't fit. Added styles for Windows High Contrast Mode.
  </p>
  <p>
    This menu also only allows for 5 primary items, and 6 secondary items per primary item, except for the first (4 items max) and the last (3 items max). I adjust the positioning on the first &amp; last sub-menus to account for the screen edge. As such, it only allows for two tiers of navigation. That's not a very extensible menu, but as I am building it for my own site, it fits my needs.
  </p>
  <p>
    Ideas for a better approach to the keyboard support scripting are appreciated. I wrote these from scratch, which guarantees they are crap.
  </p>
</main>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lato:400,700);

body {
  background-color: #6D695C;
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAACVBMVEUAAAAAAAAAAACDY+nAAAAAA3RSTlMmDQBzGIDBAAAAG0lEQVR42uXIIQEAAADCMHj/0NdkQMws0HEeAqvwAUGJthrXAAAAAElFTkSuQmCC);
  font-size: 100%;
  color: #fff;
  font-family: Lato, Arial, sans-serif;
  padding: 0;
  margin: 0;
}

main {
  display: block;
  box-sizing: border-box;
  width: 90%;
  margin: 1em auto;
  padding: 1em;
  color: #000;
  background-color: rgba(255,255,255,.25);
  border: .07em solid rgba(0,0,0,.5);
  border-radius: .5em;
}

a {
  color: #009;
}

/* The fully-expanded menu is just over 23em, so this will show another menu up to that width or height. */

@media (max-width:23em), (max-height:22em) {

  nav {
    /*border: 1px dotted #f00;*/
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    background-color: #000;
  }
  
  nav::after {
    content: "";
    display: block;
    clear: both;
  }
  
  nav h1 {
    display: none;
  }
  
  nav ol, nav li {
    margin: 0;
    padding: 0;
    list-style-type: none;
  }
  
  nav ol ol {
    display: none;
  }
  
  nav a {
    display: block;
    box-sizing: border-box;
    width: 50%;
    float: left;
    margin: 0;
    padding: 1em 0;
    text-align: center;
    color: #fff;
    background-color: #000;
    text-decoration: none;
    outline: none;
    border: .07em solid #333;
  }
  
  nav li:hover a, nav li:focus a, nav li.focus a {
    background-color: #222;
    outline: none;
  }
  
  nav>ol>li a[aria-label^="Current"], nav>ol>li:hover a[aria-label^="Current"], nav>ol>li:focus a[aria-label^="Current"] {
    color: #444;
  }
  
}

/* Short, wide display */

@media (min-width:23em) and (max-height:22em) {
  
  nav a {
    width: 33.333%;
  }
  
}

/* Short, wider display */

@media (min-width:32em) and (max-height:22em) {
  
  nav a {
    width: 25%;
  }
  
}

/* Short, wider display */

@media (min-width:40em) and (max-height:22em) {
  
  nav a {
    width: 20%;
  }
  
}

/* Short, even wider display */

@media (min-width:48em) and (max-height:22em) {
  
  nav a {
    width: 16.666667%;
  }
  
}

/* The screen is now wide and tall enough to show the entire menu without cutting anything off. */

@media (min-width:23em) and (max-width:1800px) and (min-height:22em) {

  nav {
    /*border: 1px dotted #f00;*/
    box-sizing: border-box;
    position: fixed;
    top: 0;
    right: 0;
    padding: 0;
    border-radius: 0 0 0 100%;
    width: 2em;
    height: 2em;
    /*overflow: hidden;*/
    transition: all .25s ease-in;
  }
  
  nav:hover, nav:focus, nav.focus {
    background-color: rgba(0, 0, 0, 0.4);
    width: 18em;
    height: 17em;
    outline: none;
  }
  
  nav h1 {
    box-sizing: border-box;
    font-size: 100%;
    text-transform: uppercase;
    font-weight: normal;
    /*border: 1px dotted yellow;*/
    position: fixed;
    top: 0;
    right: 0;
    margin: 0;
    padding: 1em .5em 2.3em 1.8em;
    border-left: .15em solid #fff;
    border-bottom: .15em solid #fff;
    background-color: #000;
    border-radius: 0 0 0 100%;
    z-index: 50;
  }
  
  nav ol, nav li {
    margin: 0;
    padding: 0;
    list-style-type: none;
  }
  
  nav li {
    position: absolute;
  }
  
  nav li, nav a {
    display: block;
    box-sizing: border-box;
    /*position: absolute;*/
    /*position: relative;*/
    top: -5em;
    right: -5em;
    /*border: 1px dotted #f00;*/
    transition: all 0.2s ease-in;
  }
  
  nav a {
    border-radius: 100%;
    border: .15em solid #fff;
    padding: 1.5em 0;
    width: 4.5em;
    height: 4.5em;
    overflow: hidden;
    text-align: center;
    box-shadow: 0 0 1.5em rgba(50, 50, 50, 0.75);
    color: #fff;
    background-color: #000;
    text-decoration: none;
    outline: none;
  }
  
  nav>ol>li, nav>ol>li>a {
    /* So the first tier sits on top of the second tier disk */
    z-index: 10;
  }
  
  nav li:hover a, nav li:focus a, nav li.focus a {
    background-color: #222;
    box-shadow: 0 0 1.5em rgba(0, 0, 0, 1);
    outline: none;
    position: relative;
    left: 0;
    top: auto;
    /*z-index: 25;*/
  }
  
  nav>ol>li:hover, nav>ol>li:focus, nav>ol>li.focus {
    /* Keep this to make sure only the current item appears above the disc. */
    z-index: 25;
  }
  
  /* Just hide anything beyond 5*/
  
  nav>ol>li:nth-child(n+6) {
    display: none;
  }

/* Positioning the first tier */

  nav:hover>ol>li:nth-child(1), nav:focus>ol>li:nth-child(1), nav.focus>ol>li:nth-child(1) {
    right: 13.5em;
    top: .2em;
  }
  
  nav:hover>ol>li:nth-child(2), nav:focus>ol>li:nth-child(2), nav.focus>ol>li:nth-child(2) {
    right: 12em;
    top: 4.75em;
  }
  
  nav:hover>ol>li:nth-child(3), nav:focus>ol>li:nth-child(3), nav.focus>ol>li:nth-child(3) {
    right: 9.0em;
    top: 8.5em;
  }
  
  nav:hover>ol>li:nth-child(4), nav:focus>ol>li:nth-child(4), nav.focus>ol>li:nth-child(4) {
    right: 5em;
    top: 11.25em;
  }
  
  nav:hover>ol>li:nth-child(5), nav:focus>ol>li:nth-child(5), nav.focus>ol>li:nth-child(5) {
    right: .4em;
    top: 12.5em;
  }
  
/* Positioning the second tier */
  
  nav>ol>li>ol {
    background-color: rgba(0, 0, 0, 0);
    width: 0;
    height: 0;
    display: block;
    position: absolute;
    border-radius: 100%;
    transition: all .2s ease-in;
    left: 2.25em;
    top: 2.25em;
    left: 0;
    top: 0;
    /*z-index: 1;*/
    /*border: 1px dotted yellow;*/
  }
  
  nav>ol>li:hover>ol, nav>ol>li:focus>ol, nav>ol>li.focus>ol {
    width: 15em;
    height: 15em;
    /*z-index: 1;*/
    /*top: -4.75;
    left: -4.75;*/
    margin-top: -5.25em;
    margin-left: -5.25em;
    background-color: rgba(0, 0, 0, 0.6);
  }
  
  nav>ol>li>ol>li, nav>ol>li>ol>li a {
    position: absolute;
    /*border-color: #99f;*/
    transition: all .2s ease-in;
    top: 0;
    left: 0;
    /*z-index: 1;*/
    /*left: 4.5em;
    top: 0;*/
  }
  
  nav>ol>li>ol>li a {
    border-color: #f60;
    box-shadow: none;
    transition: all .2s ease-in;
    display: none;
  }
  
  nav>ol>li:hover>ol>li, nav>ol>li:focus>ol>li, nav>ol>li.focus>ol>li {
    /*box-shadow: 0 0 1.5em rgba(50, 50, 50, 0.75);*/
    z-index: 5;
  }
  
  nav>ol>li:hover>ol>li a, nav>ol>li:focus>ol>li a, nav>ol>li.focus>ol>li a {
    background-color: #000;
    box-shadow: none;
    z-index: 5;
    display: block;
  }
  
  nav>ol>li>ol>li a:hover, nav>ol>li>ol>li a:focus {
    background-color: #222;
    box-shadow: 0 0 1.5em rgba(0, 0, 0, 1);
  }

  /* Position individual items */
  
  nav>ol>li:hover>ol>li:nth-child(1), nav>ol>li:focus>ol>li:nth-child(1), nav>ol>li.focus>ol>li:nth-child(1), nav>ol>li:nth-child(5):hover>ol>li:nth-child(3), nav>ol>li:nth-child(5):focus>ol>li:nth-child(3), nav>ol>li:nth-child(5).focus>ol>li:nth-child(3) {
    left: 2.75em;
    top: 1em;
  }

  nav>ol>li:hover>ol>li:nth-child(2), nav>ol>li:focus>ol>li:nth-child(2), nav>ol>li.focus>ol>li:nth-child(2) {
    left: 7.75em;
    top: 1em;
  }

  nav>ol>li:hover>ol>li:nth-child(3), nav>ol>li:focus>ol>li:nth-child(3), nav>ol>li.focus>ol>li:nth-child(3), nav>ol>li:nth-child(1):hover>ol>li:nth-child(1), nav>ol>li:nth-child(1):focus>ol>li:nth-child(1), nav>ol>li:nth-child(1).focus>ol>li:nth-child(1) {
    left: 10.25em;
    top: 5.25em;
  }

  nav>ol>li:hover>ol>li:nth-child(4), nav>ol>li:focus>ol>li:nth-child(4), nav>ol>li.focus>ol>li:nth-child(4), nav>ol>li:nth-child(1):hover>ol>li:nth-child(2), nav>ol>li:nth-child(1):focus>ol>li:nth-child(2), nav>ol>li:nth-child(1).focus>ol>li:nth-child(2) {
    left: 7.75em;
    top: 9.5em;
  }

  nav>ol>li:hover>ol>li:nth-child(5), nav>ol>li:focus>ol>li:nth-child(5), nav>ol>li.focus>ol>li:nth-child(5), nav>ol>li:nth-child(1):hover>ol>li:nth-child(3), nav>ol>li:nth-child(1):focus>ol>li:nth-child(3), nav>ol>li:nth-child(1).focus>ol>li:nth-child(3), nav>ol>li:nth-child(5):hover>ol>li:nth-child(1), nav>ol>li:nth-child(5):focus>ol>li:nth-child(1), nav>ol>li:nth-child(5).focus>ol>li:nth-child(1) {
    left: 2.75em;
    top: 9.5em;
  }
  
  nav>ol>li:hover>ol>li:nth-child(6), nav>ol>li:focus>ol>li:nth-child(6), nav>ol>li.focus>ol>li:nth-child(6), nav>ol>li:nth-child(1):hover>ol>li:nth-child(4), nav>ol>li:nth-child(1):focus>ol>li:nth-child(4), nav>ol>li:nth-child(1).focus>ol>li:nth-child(4), nav>ol>li:nth-child(5):hover>ol>li:nth-child(2), nav>ol>li:nth-child(5):focus>ol>li:nth-child(2), nav>ol>li:nth-child(5).focus>ol>li:nth-child(2) {
    left: .25em;
    top: 5.25em;
  }
  
  /* Just hide anything beyond 6. */

  nav>ol>li>ol>li:nth-child(n+7), nav>ol>li:hover>ol>li:nth-child(n+7), nav>ol>li:focus>ol>li:nth-child(n+7), nav>ol>li.focus>ol>li:nth-child(n+7) {
    display: none;
  }
  
  /* Hide from 5 items and up on the first menu. */
  
  nav>ol>li:nth-child(1):hover>ol>li:nth-child(n+5), nav>ol>li:nth-child(1):focus>ol>li:nth-child(n+5), nav>ol>li:nth-child(1).focus>ol>li:nth-child(n+5) {
    display: none;
  }
  
  /* Hide from 4 items and up on the last menu.*/
  
  nav>ol>li:nth-child(5):hover>ol>li:nth-child(n+4), nav>ol>li:nth-child(5):focus>ol>li:nth-child(n+4), nav>ol>li:nth-child(5).focus>ol>li:nth-child(n+4) {
    display: none;
  }

  /* Style links that are current page/section. */
  
  nav>ol>li a[aria-label^="Current"], nav>ol>li:hover a[aria-label^="Current"], nav>ol>li:focus a[aria-label^="Current"] {
    color: #666;
    border-color: #999;
  }
  
}

@media screen and (-ms-high-contrast: active) {
  nav>ol>li a[aria-label^="Current"], nav>ol>li:hover a[aria-label^="Current"], nav>ol>li:focus a[aria-label^="Current"] {
    background-color: #00c;
  }
  
}

              
            
!

JS

              
                /* For any clicks, clear the focus class from the nav and all its descendants, essentially closing the menu when a user clicks/taps outside of it. */
$(document).click(function(e) {
  $("nav *, nav").removeClass("focus");
});

/* Manipulate focus classes in navigation. */
function classy(){
  $("nav *, nav").removeClass("focus");
  $("nav:focus").addClass("focus");
  $("nav a:focus").addClass("focus");
  $("nav a:focus").parentsUntil("body").addClass("focus");
}

/* Delay the assigning of classes to give the :focus a chance to catch up. There has to be a better way for this. */
$(document).keydown(function() {
  setTimeout(classy, 200);
});

/* Find the current page and add the aria-label to its site structure parent, which you should only use if you can't do this server-side in your CMS of choice. */
$(document).ready(function() {
  var el = $("a[aria-label^='Current Page']");
  var elParent = el.parent().parent().parent("li").children("a");
  var elTxt = elParent.text();
  elParent.attr("aria-label", "Current Section: " + elTxt);
});

              
            
!
999px

Console