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>Pullup 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>Advantages</h2>
  <p>Extremely accessible for keyboard user, because it's never hidden and remains keyboard and screenreader accessible.</p>
  <p>Sidesteps checkbox hack's accessibility issue, as there's no need to toggle the menu with keyboard navigation</p>
  <p>Menu items are visible when scrolling to the end of the page, which lets users know what's available without having to click on any buttons</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 stays visible and is moved to the bottom above the footer. A toggle button is shown that pulls it up to the top as user demands.</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: CornflowerBlue;
  --clr-body: AliceBlue;
  --clr-side: #bfd0ee;
  --clr-footer: CornflowerBlue;
  --clr-btn: DarkSlateBlue;
  --clr-btn-hover: #6357a7;
  --clr-btn-txt: LightSkyBlue;
  --clr-btn-txt-hover: white;
  --clr-btn-border: #6357a7;
  --clr-skip-link: white;
  --clr-body-txt: #282342;
}

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'] {
  z-index:-1;
  position:absolute;
}

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"
      "pullup"
      "main"
      "aside"
      "nav"
      "footer";
    grid-template-columns: auto;
    grid-template-rows: repeat(3, 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,
  #nav:checked ~ header label :first-child {visibility:hidden}
  /* pullup menu */
  #nav:checked + header nav,
  header:focus-within nav {grid-area:pullup}
  /* hide label when skip link is visible */
  header:focus-within label {visibility:hidden}
}
              
            
!

JS

              
                
              
            
!
999px

Console