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

              
                <nav role="navigation" class="navigation" tabindex="0">
  <a class="navigation__link" href="http://www.alsacreations.com/">Picon bière</a>
  <a class="navigation__link" href="https://www.goetter.fr">Melfor</a>
  <a class="navigation__link" href="http://www.alsacreations.com/">Carola</a>
  <a class="navigation__link" href="https://www.goetter.fr">Wurscht</a>
  <a class="navigation__link" href="http://www.alsacreations.com/">Choucroute</a>
  <a class="navigation__link" href="https://www.goetter.fr">Knacks</a>
</nav>

<main class="main" role="main">
  
  <button class="burger-button" type="button" role="button" aria-label="open/close navigation"><i></i></button>
</header>
  
  <h1>Navigation "push left JS"</h1>
  <p>Navigation "Push Left" : au clic/tap sur le bouton burger, la partie principale se décale à droite, laissant découvrir la navigation.</p>
  <ul>
    <li>JavaScript pour le comportement "touch"</li>
    <li>CSS pour les styles et les transitions</li>
  </ul>
  <p>Le principe général est celui-ci :</p>
  <ul>
    <li>"main" s'affiche par dessus "navigation". Ce dernier étant en position absolute et z-index inférieur.</li> 
    <li>JavaScript s'occupe de l'action "touch" en ajoutant/retirant la classe ".is-opened" sur "main".</li>
  </ul>
  <p>Accessibilité :</p>
  <ul>
    <li>La navigation au clavier est possible (la méthode focus() donne le focus à la navigation après avoir actionné le bouton burger)</li>
    <li>Le bouton burger est entouré (outline) lors de la navigation clavier uniquement (pas au clic), grâce à :focus-visible</li>
  </ul>
  <p>Grid Layout est ici employé pour :</p>
  <ul>
    <li>Le bouton burger (grille de 3 rangées, avec pseudo-éléments ::before et ::after)</li>
    <li>La navigation (espacements internes grâce à gap)</li>
  </ul>
</main>
              
            
!

CSS

              
                /* Config */
:root {
  --burger-button-size: 1.8rem;
  --burger-button-thickness: 6px;
  --burger-button-color: purple;
  --nav-width: 20rem;
  --nav-bg: pink;
  --nav-link-bg: hotpink;
  --nav-link-color: #fff;
  --nav-link-hover: purple;
  --main-bg: beige;
}

/* Global layout */

html, body {
  overflow-x: hidden; /* you shall not pass! */
}

/* styling  nav */
.navigation {
  position: absolute;
  display: grid;
  align-content: start;
  gap: 2px;
  width: var(--nav-width);
  min-height: 100vh;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 0; /* will be under everything */
}

/* styling opened nav */
.main {
  transition: transform .25s;
  will-change: transform;
}
.main.is-opened {
  transform: translateX(20rem);
}

/* styling button */
.burger-button {
  appearance: none;
  all: unset;
  display: inline-grid;
  grid-template-rows: repeat(3, var(--burger-button-thickness));
  align-content: space-between;
  vertical-align: top;
  height: var(--burger-button-size);
  width: var(--burger-button-size);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.burger-button>*,
.burger-button::after, 
.burger-button::before {
  content: "";
  background: var(--burger-button-color);
}
.burger-button:focus-visible {
  /* affichage du focus lors de la navigation au clavier */
  outline: 2px dashed var(--burger-button-color);
  outline-offset: 5px;
}

/* Global deco */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
}

.main {
  padding: 2rem;
  background: var(--main-bg);
  min-height: 100vh;
}

.navigation {
  background: var(--nav-bg);
}
.navigation__link {
  padding: 1rem;
  background: var(--nav-link-bg);
  color: var(--nav-link-color);
  text-decoration: none;
}
.navigation__link:hover,
.navigation__link:focus,
.navigation__link:active {
  background: var(--nav-link-hover);
}
              
            
!

JS

              
                (function() {
function toggleNav() {
// Define targets
var target = document.querySelector('.main');
var button = document.querySelector('.burger-button');
var navigation = document.querySelector('.navigation');

// click-touch event
if ( button ) {
  button.addEventListener('click', 
  function (e) { 
    target.classList.toggle('is-opened'); 
    navigation.focus();
    e.preventDefault();
  }, false );
}
} // end toggleNav()

toggleNav();
}());
              
            
!
999px

Console