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.

Quick-add: + add another resource

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.

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="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 "push top JS"</h1>
  <p>Navigation mobile-first "Push Top" 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: #333;
}
.navigation > a {
  display: block;
  padding: 10px;
  background: rgba(255,255,255,.3);
  margin-bottom: 2px;
  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;
  left: 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 .nav-button {
    display: inline-block;
  }
  .js-enabled .navigation {
    position: absolute;
    width: 100%;
    top: 0;
    left: 0;
    z-index: 0; /* will be under everything */
  }

  /* styling opened nav */
  .js-enabled .main {
    position: relative;
    transition: transform .25s;
    will-change: transform;
  }
  .js-enabled .main.is-opened {
    transform: translateY(60vw);
  }
}

            
          
!
            
              (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('.main');
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
Loading ..................

Console