Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

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

CSS

              
                @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;
}
              
            
!

JS

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

Console