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 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.

            
              <body id="body"> <!-- body will be the .nav-button target -->

<aside class="sidebar">
  <nav id="navigation" role="navigation">
    <a href="#">Salade</a>
    <a href="#">Tomate</a>
    <a href="#">Oignons</a>
    <a href="#">Choucroute</a>
    <a href="#">Picon bière</a>
    <a href="#">Kouglopf</a>
  </nav>
</aside>
<!-- /sidebar -->

<div class="wrapper">
  
  <a href="#body" class="nav-button-open" aria-label="open navigation"></a>
  <a href="#" class="nav-button-close" aria-label="close navigation"></a>
  
  <header class="header">
    <h1>Push top CSS Nav</h1>
  </header>

  <div class="main">
    <h2>partie "main"</h2>
    <p>Navigation "off Canvas" basée sur :</p>
    <ul>
      <li>CSS pour la décoration du lien-bouton (via linear-gradients)</li>
      <li>CSS pour l'évément du "touch" (via :target)</li>
      <li>CSS pour la transition</li>
    </ul>
    <p>Le principe général est celui-ci :</p>
    <ul>
      <li>Sur grand écran (mini 768), "sidebar" est simplement placé en haut de "wrapper".</li>
      <li>Sur petit écran (maxi 767), "sidebar" passe en position absolute, "wrapper" est décalé en translation par dessus "sidebar".</li>
    </ul>
    <p>Pré-requis :</p>
    <ul>
      <li>body doit avoir un id pour être ciblé par l'ancre</li>
    </ul>
  </div>

  <footer class="footer">
    <p>My <b>footer</b>
    </p>
  </footer>
</div>
<!-- /wrapper -->
  
</body>
            
          
!
            
              /* wrapper styles */
.wrapper {
  position: relative;
  min-height: 100vh;
}

/* small screens styles */
@media (max-width: 767px) {
  .sidebar {
    position: absolute;
    top: 0; left: 0; right: 0;
  }
  
  /* navigation styles */
  nav {
    -webkit-columns: 2;
    -moz-columns: 2;
    -ms-columns: 2;
    columns: 2;
    -webkit-column-gap: 2px;
    -moz-column-gap: 2px;
    -ms-column-gap: 2px;
    column-gap: 2px;
    padding: 2px;
  }
  nav > a {
    display: inline-block;
    width: 100%;
    height: 6rem;
    line-height: 6rem;
    padding-left: 1rem;
  }
  .wrapper {
    transform: translateX(0) translateZ(0);
    transition: transform .2s;
    will-change: transform;
  }  

  /* button deco */
  [class^="nav-button"] {
    display: block;
    z-index: 1;
    height: 3.5rem; width: 3.5rem;
    background-color: transparent;
    background-image: linear-gradient(to right, #333, #333),
      linear-gradient(to right, #333, #333),
      linear-gradient(to right, #333, #333);
    background-position: center top, center, center bottom;
    background-repeat: no-repeat;
    background-size: 3.5rem .9rem;
    padding: 0;
    outline: 0;
    border: 0;
    cursor: pointer;
    -webkit-tap-highlight-color:rgba(0,0,0,0);
  }
  
  /* here's goes the push top effect */
  body:target .wrapper {
    transform: translateY(19rem); /* based on navigation's height */
  }
  .nav-button-close,
  body:target .nav-button-open {
    display: none;
  }
  .nav-button-open,
  body:target .nav-button-close {
    display: block;
  }
  
} /* end of small screen media queries */

/* Global deco */
* {
  box-sizing: border-box;
}
html {
  font-size: 62.5%;
}
body {
  margin: 0;
  padding: 0;
  color: #fff;
  font-size: 1.6em;
  font-family: arial, sans-serif;
}
a {
  color: #fff;
}
.wrapper {
  padding: 2rem;
  background-color: #eee;
  color: #333;
}
.sidebar {
  background: #333;
  color: #ddd;
}
nav a {
  margin-bottom: 2px;
  text-decoration: none;
  background: rgba(255,255,255, 0.1);
}


            
          
!
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