cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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

<div class="main" role="main">
  <button class="nav-button" role="button" type="button" aria-label="navigation"></button>
  
  <h1>Navigation "slide left JS"</h1>
  <p>Navigation mobile-first "Slide Left" librement inspiré du code du livre <a href="">Responsive Design Patterns</a> de Ethan Marcotte</p>
  <ul>
    <li>JavaScript pour le comportement "touch" et la génération du bouton de menu</li>
    <li>CSS pour les styles et les transitions</li>
  </ul>
  <p>Le principe général est celui-ci :</p>
  <ul>
    <li>Si JavaScript n'est pas activé ou si le navigateur est ancien, la navigation s'affiche simplement dans le flux, de façon accessible</li>
    <li>Sur petit écran (maxi 544px), "main" s'affiche par dessus "navigation" et le bouton de navigation "nav-button" apparaît. <br>JavaScript s'occupe de l'action "touch" en ajoutant/retirant la classe ".is-opened" sur "main".</li>
    <li>Sur grand écran (mini 545px), "navigation" est simplement placée dans le flux en haut de "main".</li>
  </ul>
  <p>Lorem Elsass ipsum réchime amet non Choucroute knack tchao bissame hopla. Wotch a kofee avec ton BibalaekaesSalat et ta wurscht ?</p>
  <p>Yeuh non che suis au réchime, je ne mange plus que des Grumbeere light et che fais de la chym avec Chulien. Tiens, un Picon sur le comptoir.</p>
  <p>Allez tchao bissame !</p>
</div>
            
          
!
            
              /* Global deco */

* {
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
  font-size: calc(1em * .625);
}

body {
  margin: 0;
  font-size: 1.6em;
  font-family: arial, sans-serif;
}

.main {
  padding: 5rem 2rem;
  background: #fff;
}

/* Global layout */

.navigation {
  background: rgba(0,0,0,.5);
}
.navigation > a {
  display: block;
  padding: 2rem 1rem;
  background: #333;
  color: #fff;
  text-decoration: none;
}
.navigation > a:hover,
.navigation > a:focus,
.navigation > a:active {
  background: #555;
}

.nav-button {
  display: none; /* no button by default */
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1; /* will be above everything */
  height: 2.4rem;
  width: 2.8rem;
  background-color: transparent;
  background-image: linear-gradient(to right, currentColor, currentColor);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 5px;
  padding: 0;
  outline: 0;
  border: 0;
  color: #333;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-button::before,
.nav-button::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  display: block;
  height: 5px;
  background: currentColor;
  transition: .25s;
  transition-property: transform, top;
  will-change: transform, top;
}
.nav-button::before {
  top: 0;
}
.nav-button::after {
  top: calc(100% - 4px);
}


@media (max-width: 545px) {
  .js-enabled html,
  .js-enabled body {
    overflow-x: hidden; /* you shall not pass! */
  }
  .js-enabled .nav-button {
    display: inline-block;
  }
  .js-enabled .navigation {
    position: absolute;
    width: 60vw;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
  }

  /* styling opened nav */
  .js-enabled .navigation {
    transition: transform .25s;
    will-change: transform;
    transform: translateX(-100%);
  }
  .js-enabled .navigation.is-opened {
    transform: translateX(0);
  }
}

            
          
!
            
              (function() {

// old browser or not ?
if ( !('querySelector' in document && 'addEventListener' in window) ) {
return;
}
window.document.documentElement.className += ' js-enabled';

function toggleNav() {

// Define targets
var target = document.querySelector('.navigation');
var button = document.querySelector('.nav-button');

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

toggleNav();
}());
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console