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.
<div class="wrap-all-the-things">
<header class="main-head">
<h1>Header</h1>
<nav>Home | About | Portfolio | Contact</nav>
</header>
<section class="main-torso">
<article class="main-torso__group main-torso__group--margin-bottom">
<div class="main-torso__inner">
<h2>Scroll Down</h2>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
</div>
</article>
<article class="main-torso__group main-torso__group--margin-bottom">
<div class="main-torso__inner">
<h2>Keep Scrolling</h2>
<p>Pellentesque ut neque. Etiam sit amet orci eget eros faucibus tincidunt. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Cras varius. Nam at tortor in tellus interdum sagittis.</p>
<p>Phasellus ullamcorper ipsum rutrum nunc. Etiam feugiat lorem non metus. In hac habitasse platea dictumst. Nam ipsum risus, rutrum vitae, vestibulum eu, molestie vel, lacus. Curabitur suscipit suscipit tellus.</p>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
</div>
</article>
<article class="main-torso__group">
<div class="main-torso__inner">
<h2>Almost There</h2>
<h3><em>There's a sticky section just under this one that will become fixed to the bottom of the screen once it's fully in view.</em></h3>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
</div>
</article>
<article id="js-foot-cta" class="main-torso__group foot-cta">
<a href="javascript:void(0);" class="foot-cta__link">Sticky Stopper</a>
</article>
<article class="main-torso__group">
<div class="main-torso__inner">
<h2>But Wait: There's More</h2>
<h3>Keep on scrolling...</h3>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
</div>
</article>
<article class="main-torso__group">
<div class="main-torso__inner">
<h2>Check Out the Footer</h2>
<h3><em>Once it comes into view, the sticky section becomes fixed to the top of the footer.</em></h3>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
<p>Pellentesque posuere. Integer tincidunt. Praesent metus tellus, elementum eu, semper a, adipiscing nec, purus. Sed libero. Etiam feugiat lorem non metus.</p>
<p>Etiam iaculis nunc ac metus. Praesent vestibulum dapibus nibh. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Morbi ac felis. Nam eget dui.</p>
</div>
</article>
</section>
<footer id="js-foot" class="main-foot">
<p><strong>Footer</strong></p>
<p>Pretty Cool, Huh?</p>
<nav>Home | About | Portfolio | Contact</nav>
</footer>
</div>
@import url(https://fonts.googleapis.com/css?family=Raleway:400,900);
$vert-margin: 5em;
/*------------------------------------*\
::Page Footer CTA Template Part
\*------------------------------------*/
.foot-cta {
position: relative;
z-index: 50;
height: $vert-margin;
text-align: center;
}
.foot-cta--sticky {
.foot-cta__link {
position: fixed;
bottom: 0;
}
}
.foot-cta__link {
position: absolute;
left: 0;
width: 100%;
height: $vert-margin;
background-color: rgba(#6D9F94,.8);
line-height: 2.5;
color: #FCFEBE;
text-decoration: none;
transition: 300ms;
&:hover {
background-color: rgba(#FCFEBE,.8);
color: #C9AF59;
}
}
html, body {
height: 99.99999%;
}
.wrap-all-the-things {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
background-color: #215D6E;
color: #FCFEBE;
font-family: "Raleway", "Trebuchet MS", sans-serif;
}
.main-head, .main-torso, .main-foot, .foot-cta__spacer {
display: table-row;
}
.main-head {
background-color: #387179;
text-align: center;
&:after {
content: "";
background-color: #6D9F94;
height: .2em;
width: 100%;
margin-top: 5em;
display: block;
}
}
.main-torso {
height: auto;
background-color: #215D6E;
p {
color: #6D9F94;
}
h3 {
font-weight: 100;
}
}
.main-foot {
background-color: #387179;
text-align: center;
&:before {
content: "";
background-color: #6D9F94;
height: .2em;
width: 100%;
margin-bottom: 5em;
display: block;
}
}
[class*="__inner"] {
max-width: 1140px;
margin: {left: auto; right: auto;}
padding: {left: 1em; right: 1em;}
}
[class*="--margin-bottom"] {
margin-bottom: $vert-margin;
}
//prepost jquery plugin
(function($) {
$.fn.stickystop = function(options) {
var stick = {
//prepare to store jquery objects
win: null,
cta: null,
stopper: null,
//to store timer
timer: null,
//to store options
//options passed into the plugin
opt: $.extend({
//the inner element
inner: '> :first-child',
//the stopper element
stopper: '.stickystop__stopper'
}, options),
//initialize the sticky cta
init: function(stickEl){
stick.cta = stickEl;
if(stick.cta.length > 0){
//cache variables
stick.win = $(window);
stick.inner = stick.cta.find(stick.opt.inner);
stick.stopper = $(stick.opt.stopper);
stick.stopper.before('<div class="foot-cta foot-cta__spacer"><!-- spacer for sticky cta --></div>');
//work on scroll
stick.win.on('scroll',function(){
//be at least a little more performant
clearTimeout(stick.timer);
stick.timer = setTimeout(stick.move, 5);
});
}
},
//when the user scrolls
move: function(){
// get the top
var winTop = stick.win.scrollTop();
// get the bottom
var winBot = winTop + stick.win.height();
// get the cta top
var ctaTop = stick.cta.offset().top;
// get the cta bottom
var ctaBot = ctaTop + stick.cta.height();
// get the stopper top
var stopperTop = stick.stopper.offset().top;
// if the cta's bottom is in view and the top of the stopper isn't
if(ctaBot <= winBot && winBot <= stopperTop){
// make the cta sticky (to the bottom)
stick.cta.addClass('foot-cta--sticky');
stick.inner.css('top', 'auto');
// if the top of the footer is in view
} else if (winBot > stopperTop){
// absolute position the cta above the stopper
stick.cta.removeClass('foot-cta--sticky');
stick.inner.css('top', (stopperTop - ctaBot));
// if the bottom of the cta is not in view
} else {
// absolute position the cta at the top of it's origin
stick.cta.removeClass('foot-cta--sticky');
stick.inner.css('top', 0);
}
}
};
//initialize the slider for the object passed in
stick.init(this);
};
}(jQuery));
//call prepostslider on an element (all options set to default)
jQuery(function($){
$('#js-foot-cta').stickystop({
//inner: '.foot-cta__link', //defaults to '> :first-child'
stopper: '#js-foot' //defaults to .stickystop__stopper
});
});
Also see: Tab Triggers