cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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.

            
               <head>
    <title>Off-canvas nav demo</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="off-canvas.css">

  </head>

  <body>

    <nav class="nav-primary" id="nav-primary">

      <ul>
        <li><a href="#">Item 1</a></li>
        <li><a href="#">Item 2</a></li>
        <li><a href="#">Item 3</a></li>
        <li><a href="#">Item 4</a></li>
        <li><a href="#">Item 5</a></li>
      </ul>

    </nav>

    <header class="mobile-helper-bar">
      <button class="hamburger" id="off-canvas-toggle">&#9776;</button>
    </header>

    <div class="page-content" id="page-content">

    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    </div>
            
          
!
            
              @import "compass/css3";

/*  ==========================================================================
		CORE STYLES
		This should work just fine as long as you @include off-canvas-nav in your
		.nav-primary.
		========================================================================== */
		
$off-canvas-width: 16rem;
$off-canvas-duration: .3s;
$canvas-offset: .5;

@mixin off-canvas-nav {
	position: fixed;
	top: 0;
	left: 0;
	bottom: 0;
	z-index: 2;
	overflow-y: auto;
	width: $off-canvas-width;
	@include transition($off-canvas-duration);
  @include transform(translateX(-$off-canvas-width));
	
	&.off-canvas-show {
		@include transform(translateX(0));
	}

	@media screen and (min-width: 768px) {
		position: static;
		display: block;
		margin: 0;
		padding: 0;
		width: 100%;
		@include transform(translateX(0));
	}
}

.page-content,
.mobile-helper-bar {
	float: right;
	width: 100%;
	@include transition($off-canvas-duration);
}

.off-canvas-show {
	~ .page-content {
		overflow: hidden;
		@include transform(translateX($off-canvas-width*$canvas-offset));
	}
	~ .mobile-helper-bar {
		overflow: hidden;
		@include transform(translateX($off-canvas-width));
	}
}

.mobile-helper-bar {
	background: #ccc;
	position: fixed;
	z-index: 1;
	padding: .5rem 1rem;
	@media screen and (min-width: 768px) {
		display: none;
	}
	button { color: #fff; }
}

/*  ==========================================================================
		DEMO THEME
		These are just separated out to keep the core styles a little bit cleaner.
    ========================================================================== */
    
body {
	padding: 0;
	margin: 0;
	font-family: sans-serif;
}

.nav-primary {
	background: #333;
	@include off-canvas-nav;
	
	ul {
		text-align: left;
		@media screen and (min-width: 768px) {
			text-align: center;
		}
	}
	
	li {
		display: block;
		padding: .5rem 0;
		line-height: 1;
		list-style: none;
		@media screen and (min-width: 768px) {
			display: inline-block;
			padding: .25rem 2rem;
		}
	}
	
	a {
		color: #fff;
		font-family: Avenir, Helvetica Neue, sans-serif;
		font-weight: bold;
		text-decoration: none;
		padding: .5rem 0;
		display: block;
	}
	
}

.off-canvas-show {
	box-shadow: 0 0 5px #000;
}

.page-content {
	padding: 3rem 1rem;
	box-sizing: border-box;
	@media screen and (min-width: 768px) {
		padding: 3rem;
	}
}



.hamburger {
	background: transparent;
	font-size: 1.5rem;
	border: 0;
	outline: none;
	display: inline-block;
	padding: 0;
	margin: 0;
}
            
          
!
            
              // Show the off-canvas navigation
$('#off-canvas-toggle').click(function() {
	$('#nav-primary').toggleClass('off-canvas-show');
});


// Hide the off-canvas nav when clicking a link
$('#nav-primary').find('a').on('click', function(e) {
	$('#nav-primary').removeClass('off-canvas-show');
});
            
          
!
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