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

              
                <input type="checkbox" id="nav">
<header>
  <sm-header>
    <h1>Overlay Menu</h1>
    <sm-nav>
      <a href="#skip">Skip to Content</a>
      <label for="nav"><span>Menu</span><span>Dismiss</span></label>
    </sm-nav>
  </sm-header>
  <nav>
    <a href="#item1">Item One</a>
    <a href="#item2">Item Two</a>
    <a href="#item3">Item Three</a>
    <a href="#item4">Item Four</a>
  </nav>
</header>
<main id="skip">
  <h2>Automatic Dropdown Menu</h2>
  <p>Extremely accessible for keyboard user, menu always keyboard and screen-reader accessible.</p>
  <p>Sidesteps checkbox hack's accessibility issue, as there's no need to toggle the menu with keyboard navigation.</p>
  <p>Menu only visible when keyboard focus is in header.</p>
  <a href="#">Focus Test 1</a>
  <h2>Implementation</h2>
  <p>It can be implemented with both Grid (changing grid-area) and Flexbox (changing order), but Grid is usually easier.</p>
  <p>Checkbox hack (for mouse and touch) and <code>nav:focus-within</code> (for keyboard) are used to toggle the grid-area property of the mobile navigation.</p>
  <h2>Bonus Features</h2>
  <ul>
    <li>Hidden "Skip to Content" link</li>
    <li>Prevent layout shift using overlapping grid items</li>
  </ul>
  <p></p>
</main>
<aside>
  <h2>Behaviour</h2>
  <p>Menu pops over the content when label is clicked or when keyboard focus is in header, so when focus moves behind the menu the menu collapses.</p>
  <a href="#">Focus Test 2</a>
</aside>
<footer>
  Footer
</footer>
              
            
!

CSS

              
                /* 100% height */
html {
    height:100%;
    display: flex;
    flex-direction:column;
}
body {
    width:100%;
    flex-grow:1;
    flex-basis:0;
}
html, body {margin:0;padding:0;}

/* color scheme */
:root {
  --clr-header: #ff8caf;
  --clr-body: #e6e0e2;
  --clr-side: #d9ced2;
  --clr-footer: #ff8caf;
  --clr-btn: #c5486e;
  --clr-btn-hover: #ab3a5c;
  --clr-btn-txt: #f7cdda;
  --clr-btn-txt-hover: white;
  --clr-btn-border: #a13354;
  --clr-skip-link: white;
  --clr-body-txt: #302528;
}

body > * {padding: 1rem}
h1 {font-size: 1.4rem; margin:0}
h2 {font-size: 1.2rem}

/* pull up menu */
body {
  display:grid;
  grid-template-areas: 
    "header header"
    "main   aside"
    "footer footer";
  grid-template-rows:  auto 1fr auto;
  grid-template-columns: 2fr 1fr;
  font-family: sans-serif;
  color: var(--clr-body-txt);
}

input#nav,
header label {display:none}

header {grid-area:header; background:var(--clr-header)}
main   {grid-area:main;   background:var(--clr-body)}
aside  {grid-area:aside;  background:var(--clr-side)}
footer {grid-area:footer; background:var(--clr-footer)}

header {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:space-between;
  gap:1rem;
}

sm-header {display:flex; gap: 1rem; align-items:center}

a[href='#skip'] {
  font-weight:bold;
  color:var(--clr-skip-link);
  text-align:right
}
header:not(:focus-within) a[href='#skip'] {
  position:absolute; z-index:-1;
}
nav {
  display:flex;
  flex-wrap:wrap;
  justify-content:flex-end;
  gap:.5rem .75rem
}
nav a {
  padding:.3rem .6rem;
  background:var(--clr-btn);
  color: var(--clr-btn-txt);
  text-decoration:none;
  border-radius:.4rem;
}
nav a:hover,
nav a:active,
header label:hover span,
header label:active span  {
  background:var(--clr-btn-hover);
  color:var(--clr-btn-txt-hover);
}

@media (max-width: 768px) {
  body {
    grid-template-areas: 
      "header"
      "nav"
      "main"
      "aside"
      "footer";
    grid-template-columns: auto;
    grid-template-rows: auto 0 1fr;
  }
  /* switch header wrapper */
  header {display:contents}
  sm-header {
    grid-area:header;
    background:var(--clr-header);
    padding:1rem;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:1rem;
  }
  /* keep toggle label span the same size */
  header label {
    display:grid;
    grid-template-areas:"label";
    font-weight:bold;
    color:white;
    cursor:pointer;
    user-select:none
  }
  header label span {
    grid-area:label;
    text-align:center;
    background: var(--clr-btn);
    padding: .5rem;
    border-radius:.5rem;
    align-self:center;
    color:var(--clr-btn-txt)
  }
  /* keep toggle label and skip link the same size */
  sm-nav {
    display:grid;
    align-items:center;
    justify-items:flex-end;
  }
  sm-nav > * {grid-area:overlap}
  /* vertical menu styling */
  nav {
    grid-area:nav;
    flex-direction:column;
    gap:0;
    position:relative; height:fit-content;
    flex-wrap:nowrap;justify-content:flex-start;
  }
  nav a {
    padding:.75rem 1rem;
    border-radius:0
  }
  nav a:not(:last-child) {
    border-bottom:1px solid var(--clr-btn-border);
  }
  /* prevent outline from being cut off */
  nav a:focus {
    outline-offset:-2px;
  }
  /* logic */
  /* toggle label using visibility to prevent layout shift */
  #nav:not(:checked) ~ header label :last-child  {visibility:hidden}
  #nav:checked ~ header label :first-child {visibility:hidden}
  /* pullup menu */
  #nav:not(:checked) + header:not(:focus-within) nav {
    border:0;
    clip-path: inset(50%);
    height:1px; width:1px;
    margin:-1px;
    overflow: hidden;
    padding:0;
    position:absolute;
    white-space: nowrap;
  }
  /* hide label when skip link is visible */
  header:focus-within label {visibility:hidden}
}
              
            
!

JS

              
                
              
            
!
999px

Console