Pen Settings

HTML

CSS

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.

+ 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

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.

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

              
                <header>
	<div class="hero">
		<h1>Sticky Nav Example</h1>
	</div>
</header>
<nav class="main_nav">
	<div class="main_nav_wrap me_sticky">
		<ul class="menu">
			<li><a href="#">Home</a></li>
			<li><a href="#">Services</a></li>
			<li><a href="#">Portfolio</a></li>
			<li><a href="#">About</a></li>
		</ul>
	</div>
</nav>
<div class="section">
	<div class="page_wrap">
		<h2>Goodbye, friends. I never thought I'd die like this. But I always really hoped.</h2>
		<p>Tell them I hate them. Say what? Hello Morbo, how's the family? Oh right. I forgot about the battle.</p>
		<p>Ah, computer dating. It's like pimping, but you rarely have to use the phrase "upside your head. " I don't 'need' to drink. <strong> I can quit anytime I want!</strong> <em> Check it out, y'all.</em> Everyone who was invited is here.</p>
		<h3>Oh, all right, I am. But if anything happens to me, tell them I died robbing some old man.</h3>
		<p>Goodbye, friends. I never thought I'd die like this. But I always really hoped. Check it out, y'all. Everyone who was invited is here. Oh, I think we should just stay friends. It's toe-tappingly tragic!</p>
		<ol>
		<li>Wow, you got that off the Internet? In my day, the Internet was only used to download pornography.</li><li>You, minion. Lift my arm. AFTER HIM!</li><li>Bender, you risked your life to save me!</li>
		</ol>

		<h3>And I'm his friend Jesus.</h3>
		<p>I barely knew Philip, but as a clergyman I have no problem telling his most intimate friends all about him. She also liked to shut up! Well, let's just dump it in the sewer and say we delivered it. Come, Comrade Bender! We must take to the streets!</p>
		<ul>
		<li>And I'd do it again! And perhaps a third time! But that would be it.</li><li>Kids have names?</li><li>When the lights go out, it's nobody's business what goes on between two consenting adults.</li>
		</ul>

		<p>I didn't ask for a completely reasonable excuse! I asked you to get busy! Yeah, and if you were the pope they'd be all, "Straighten your pope hat." And "Put on your good vestments." I love you, buddy! Now Fry, it's been a few years since medical school, so remind me. Disemboweling in your species: fatal or non-fatal?</p>
		<p>I don't know what you did, Fry, but once again, you screwed up! Now all the planets are gonna start cracking wise about our mamas. Bender! Ship! Stop bickering or I'm going to come back there and change your opinions manually!</p>
		<p>How much did you make me? Why would I want to know that? Actually, that's still true. Would you censor the Venus de Venus just because you can see her spewers? Oh, how awful. Did he at least die painlessly? …To shreds, you say. Well, how is his wife holding up? …To shreds, you say.</p>
		<p>Guess again. Oh sure! Blame the wizards! Look, everyone wants to be like Germany, but do we really have the pure strength of 'will'? Leela, are you alright? You got wanged on the head. Now that the, uh, garbage ball is in space, Doctor, perhaps you can help me with my sexual inhibitions?</p>
		<p>You seem malnourished. Are you suffering from intestinal parasites? Wow! A superpowers drug you can just rub onto your skin? You'd think it would be something you'd have to freebase. Why did you bring us here?</p>
		<p>Ok, we'll go deliver this crate like professionals, and then we'll go ride the bumper cars. Hey! I'm a porno-dealing monster, what do I care what you think? Hey, tell me something. You've got all this money. How come you always dress like you're doing your laundry?</p>
		<p>Whoa a real live robot; or is that some kind of cheesy New Year's costume? And so we say goodbye to our beloved pet, Nibbler, who's gone to a place where I, too, hope one day to go. The toilet. A sexy mistake.</p>
		<p>You mean while I'm sleeping in it? Yes, except the Dave Matthews Band doesn't rock. And yet you haven't said what I told you to say! How can any of us trust you? I'll get my kit!</p>
		<p>All I want is to be a monkey of moderate intelligence who wears a suit… that's why I'm transferring to business school! Robot 1-X, save my friends! And Zoidberg! Bender! Ship! Stop bickering or I'm going to come back there and change your opinions manually!</p>
		<p>We'll go deliver this crate like professionals, and then we'll go home. You mean while I'm sleeping in it? With gusto. Can I use the gun? This opera's as lousy as it is brilliant! Your lyrics lack subtlety. You can't just have your characters announce how they feel. That makes me feel angry!</p>
		<p>Anyone who laughs is a communist! Perhaps, but perhaps your civilization is merely the sewer of an even greater society above you! This opera's as lousy as it is brilliant! Your lyrics lack subtlety. You can't just have your characters announce how they feel. That makes me feel angry!</p>
	</div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Lato:100,400,700');

$dark_gray: #414141;
html {
	font-size: 16px;
}

body {
	margin: 0;
	padding: 0;
	font-family: lato, sans-serif;
	color: $dark_gray;
	font-size: 1rem;
	min-height: 5000px;
}

h1, h2, h3, h4, h5, h6 {
	font-family: lato, sans-serif;
	font-weight: bold;
}

p {
	font-size: 1rem;
}

a {
	color: #3498db;
	text-decoration: none;
	&:hover {
		text-decoration: underline;
	}
}

header {
	.hero {
		background-color: #08AEEA;
		background-image: linear-gradient(0deg, #08AEEA 0%, #2AF598 100%);
		width: 100%;
		height: 50vh;
		min-height: 230px;
		display: flex;
		justify-content: center;
		align-items: center;
		h1 {
			margin: 0;
			color: #fff;
		}
	}
}

nav.main_nav {
	min-height: 63px; // so that the page does not jump around with postion change.
	.main_nav_wrap {
		width: 100%;
		display: block;
		background-color: $dark_gray;
		ul {
			margin: 0;
			padding: 0;
			display: flex;
			flex-wrap: wrap;
			justify-content: center;
			list-style: none;
			li {
				a {
					font-size: 1.2rem;
					padding: 20px;
					display: block;
					color: #fff;
					transition: all 0.3s;
					background-color: transparent;
					&:hover {
						text-decoration: none;
						background-color: lighten($dark_gray, 10);
					}
				}
			}
		}
	}
}

.section {
	
}

.page_wrap {
	width: 95%;
	max-width: 1000px;
	display: block;
	margin: 0 auto;
}
              
            
!

JS

              
                // can play with the offset value to get the smooth results you are looking for.

var stickyEl = document.querySelector('.me_sticky')
var stickyPosition = stickyEl.getBoundingClientRect().top;
var offset = -20
window.addEventListener('scroll', function() {
    if (window.pageYOffset >= stickyPosition + offset) {
        stickyEl.style.position = 'fixed';
        stickyEl.style.top = '0px';
    } else {
        stickyEl.style.position = 'static';
        stickyEl.style.top = '';
    }
});
              
            
!
999px

Console