cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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="http://www.goetter.fr">Melfor</a>
  <a href="http://www.alsacreations.com/">Carola</a>
  <a href="http://www.goetter.fr">Wurscht</a>
  <a href="http://www.alsacreations.com/">Choucroute</a>
  <a href="http://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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console