HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
@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;
}
// 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 = '';
}
});
Also see: Tab Triggers