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.

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

              
                <nav role="navigation" id="menu" aria-label="Main menu">
    <ul>
        <li class="droplink"><a href="" aria-haspopup="true">Dropdown 1</a>
          <ul class="subdrop" aria-label="Main Links Sub Navigation">
            <li><a href="">Sub Link 1</a></li>
            <li><a href="">Sub Link 2</a></li>
            <li><a href="">Sub Link 3</a></li>
            <li><a href="">Sub Link 4</a></li>
          </ul>
      </li>
      <li><a href="">Test Link 1</a></li>
      <li><a href="">Test Link 2</a></li>
      <li><a href="">Test Link 3</a></li>
  </ul>
</nav>

<main>
<h1 class="header">Screen Reader Friendly CSS Dropdown Menu</h1>
<p>This dropdown navigation bar is pure CSS, so will work if the user has disabled javascript. Designed for screen reader and keyboard users, it is lightweight and should be easy to style.</p>

<p>It can be tabbed through with a keyboard. The mouse does not need to hover on the dropdown link in order for the sub links to stay visible. Shift-tabbing will move focus to the previous link, or the previous dropdown link, not the sub link. Pressing the enter key when focused on a link will move to that link.</p>

<p>This does not fix mobile-friendliness, which dropdowns are not by default. A workaround would be to keep the dropdown link empty, or link it to a page that has the links made inaccessible on it such as a site map.</p>

<h1 class="header">This will scroll!</h1>
<p>The other thing with Lorem Ipsum is that you have to take out its family. We have so many things that we have to do better... and certainly ipsum is one of them. I will write some great placeholder text – and nobody writes better placeholder text than me, believe me – and I’ll write it very inexpensively. I will write some great, great text on your website’s Southern border, and I will make Google pay for that text. Mark my words. You're telling the enemy exactly what you're going to do. No wonder you've been fighting Lorem Ipsum your entire adult life.</p>

<p>Some people have an ability to write placeholder text... It's an art you're basically born with. You either have it or you don't. Trump Ipsum is calling for a total and complete shutdown of Muslim text entering your website. You have so many different things placeholder text has to be able to do, and I don't believe Lorem Ipsum has the stamina. Does everybody know that pig named Lorem Ipsum? She's a disgusting pig, right?</p>

<p>I think the only difference between me and the other placeholder text is that I’m more honest and my words are more beautiful. You have so many different things placeholder text has to be able to do, and I don't believe Lorem Ipsum has the stamina.</p>

<p>I’m the best thing that ever happened to placeholder text. Lorem Ipsum is unattractive, both inside and out. I fully understand why it’s former users left it for something else. They made a good decision. I will write some great placeholder text – and nobody writes better placeholder text than me, believe me – and I’ll write it very inexpensively. I will write some great, great text on your website’s Southern border, and I will make Google pay for that text. Mark my words.</p>

<p>This placeholder text is gonna be HUGE.</p>
</main>
              
            
!

CSS

              
                /* Some basic styling */
:root {
    --bg-color: #111;
    --txt-color: #eee;
    --link-color: #374c5d;
    --link2-color: #fff;
    --darktxt-color: #a0a0a0;
    --accent1-color: #232323;
    --accent2-color: #252D34;
    --nav-height: 35px;
}

*, html {font-size: 16px; line-height: 150%;}
body {background: var(--bg-color); color: var(--txt-color);font-family: arial, sans-serif;font-size: 1rem;}

h1, h2, h3, h4, h5, h6 {
    display: block;
    font-size: inherit;
    font-weight: inherit;
    padding: 0;
    margin: 5px 0;
}
p {
    font-size: 1rem;
    margin: 5px 0;
    padding: 0;
    text-indent: 30px;
}

.header {
    background: var(--accent1-color);
    border-bottom: 10px solid var(--accent2-color);
    color: var(--darktxt-color);
    font-family: georgia, serif;
    font-size: 1.5rem;
    font-weight: bold;
    letter-spacing: 2px;
    margin-top:20px;
    padding: 8px 2px;
    text-align: center;
}

main {
    border:2px solid var(--link-color);
    margin-top: var(--nav-height);
    margin-bottom: 0px;
    padding: 0 15px;
}

/* The Dropdown Menu */
#menu {
    width: 100%;
    height: var(--nav-height);
    text-align: center;
    padding: 0;
    background: #000;
    display: block;
    top: 0px;
    left: 0px;
    position: fixed;
    z-index: 2;
}

/*  List element styles */
#menu ul, #menu li {
  list-style: none;
  padding: 0;
  margin: 0;
  display: inline-block;
}
#menu li {
    padding: 5px 0px;
}

/* Main menu links */
#menu a:link, #menu a:visited, #menu a:active { 
    text-decoration: none;
    color: var(--link2-color); 
    padding: 5px 7px;
    font-weight: bold;
    position: relative;
    z-index: 2;
}

#menu a:hover, #menu a:focus { 
    background-color: var(--link-color);
    color: var(--link2-color); 
    text-decoration: underline; 
}

/* The submenu links container*/
.subdrop { 
    background: var(--bg-color);
    height: 0;
    border-top: 0;
    min-width: 100%;
    left: 0;
    margin: 0;
    position: absolute;
    text-align: left;
    top: 100%;
    visibility: hidden;
    height: 1px;
    overflow: hidden;
    z-index: 10;
}

/* Dropdown Parent Link Style */
.droplink {
    display: inline-block;
    min-width: fit-content;
    position: relative;
}

/* List elements within the dropdown */
.subdrop li {
    display: block!important;
    padding: 0!important;
}

/* Links within the dropdown list */
.subdrop a {
    display: block;
    padding: 12px 20px;
    white-space: nowrap;
}

/* Allows links to show on hover/focus and through keyboard navigation via focus-within */
.droplink:hover .subdrop { 
    visibility: visible;
    height: auto;
    z-index: 11;
}
/* Separate these to avoid IE completely ignoring the css above */
.droplink:focus-within .subdrop { 
    visibility: visible;
    height: auto;
    z-index: 11;
}
              
            
!

JS

              
                    
              
            
!
999px

Console