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

              
                <input type="checkbox" id="nav">
<header>
  <sm-header>
    <h1>Hideaway 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 does not cover up content, preventing focus from going behind it.</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>Mobile menu auto-expands between header and content when the header receives focus.</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: #4dc26e;
  --clr-body: #e4ebe6;
  --clr-side: #c2d1c6;
  --clr-footer: #4dc26e;
  --clr-btn: #277755;
  --clr-btn-hover: #36976e;
  --clr-btn-txt: #b4f3c6;
  --clr-btn-txt-hover: white;
  --clr-btn-border: #34916a;
  --clr-skip-link: white;
  --clr-body-txt: #1b3b2d;
}

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);
  z-index:-1;
  position:absolute;
}
header:focus-within a[href='#skip'] {position:static; z-index:0; text-align:right}

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