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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<nav>
<div class="nav-actions">
<ul>
<li>Secondary Link 1</li>
<li>Secondary Link 2</li>
<li>Secondary Link 3</li>
</ul>
<div class="clear"></div>
</div>
<div class="nav-main">
<div class="logo">Awesome logo</div>
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
<div class="clear"></div>
</div>
</nav>
<div class="content">
<section>
<div class="contained">
<h1>Fixed nav + scroll behavior</h1>
<p>
This is an experiment with a fixed navigation bar that shows/hides
part of itself based on scroll direction.
</p>
<p>
The navigation consists of two parts: the main navigation bar +
a bar with some secondary links. The main navigation is always visible, but the
secondary links are hidden/revealed when the user scrolls down/up.
A scrolling threshold must be reached before the hide/reveal interaction
takes place.
</p>
<p>
I'm not sure what name to use to describe this type of navigation.
I'm sure a name exists, as I doubt I'm the first one to implement
this type of behavior, but I just don't know it. I was inspired by
the interaction on Facebook's iPhone app. The difference here is that
part of the navigation is "sticky" while the other part scrolls
with the browser window.
</p>
<p>
If you know a term that describes this behavior, feel free to tweet
me at @wosephjeber.
</p>
<h2>And now for some filler text</h2>
<p>
Mumblecore Banksy Brooklyn 8-bit Vice. Semiotics Austin lomo you probably haven't heard of them ugh, scenester meditation Neutra banh mi master cleanse Carles migas disrupt. Next level drinking vinegar chia, try-hard scenester XOXO vegan post-ironic listicle +1 pug before they sold out. Health goth banh mi whatever, migas paleo Pinterest street art tousled fap. Trust fund Truffaut readymade quinoa, hoodie paleo cray heirloom lomo tattooed aesthetic flexitarian. Try-hard Godard hoodie, sartorial cornhole keffiyeh Bushwick Etsy art party retro swag post-ironic. Marfa food truck crucifix, health goth umami next level Shoreditch actually XOXO bespoke scenester heirloom McSweeney's selfies locavore.
</p>
<p>
Food truck actually Banksy, post-ironic kogi leggings 8-bit. Flexitarian occupy tofu American Apparel, normcore McSweeney's High Life. Four loko pickled cred stumptown vinyl. Pinterest Tumblr Helvetica, tattooed direct trade Vice vinyl Etsy. Pour-over mlkshk swag, freegan fingerstache food truck master cleanse aesthetic normcore artisan before they sold out Brooklyn. Meggings ugh Vice, wayfarers Echo Park viral PBR salvia blog church-key chambray. Lumbersexual DIY bicycle rights squid, single-origin coffee brunch raw denim plaid before they sold out irony.
</p>
<p>
Cold-pressed cronut tofu dreamcatcher, Pitchfork retro Pinterest literally jean shorts sartorial pork belly gluten-free mixtape quinoa. Carles ennui master cleanse butcher, salvia leggings viral readymade. Actually kale chips pork belly Marfa. Disrupt blog meggings Austin. Meggings iPhone flexitarian, mlkshk ennui Banksy Brooklyn fap mixtape Truffaut art party sriracha scenester hella Carles. DIY selvage hoodie, four loko occupy 3 wolf moon seitan twee bicycle rights wayfarers keffiyeh Thundercats Etsy taxidermy. Before they sold out normcore cred single-origin coffee meh cronut stumptown, Blue Bottle Vice pork belly quinoa Wes Anderson ethical next level.
</p>
<p>
Banjo hashtag Echo Park Williamsburg pickled, gentrify scenester. Aesthetic banjo Portland chillwave letterpress seitan selfies gluten-free, leggings mumblecore Etsy keffiyeh. Art party seitan sartorial deep v squid, 90's listicle. Mixtape selvage four loko, dreamcatcher Portland tattooed plaid kogi. Gluten-free cred sartorial YOLO keytar fixie. Lomo asymmetrical four loko Helvetica pork belly, forage four dollar toast post-ironic. Farm-to-table Williamsburg fanny pack, 3 wolf moon church-key cray selfies.
</p>
</div>
</section>
</div>
<script type="text/javascript" src="nav.js"></script>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
font-family: 'Open Sans', Arial, sans-serif;
color: #333;
background-color: #fdfdfd;
}
p {
line-height: 1.75;
}
section {
padding: 40px;
}
.content {
margin-top: 80px;
}
.contained {
width: 36em;
margin: 0 auto;
}
@media (max-width: 41em) {
.contained {
width: 100%;
}
}
.clear {
clear: both;
}
nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #efeeea;
}
nav .nav-main {
padding: 10px 20px;
}
nav .nav-actions {
padding: 10px 20px;
background-color: #222;
}
nav .logo {
float: left;
line-height: 50px;
font-size: 1.5em;
font-weight: bold;
text-transform: uppercase;
}
nav ul {
float: right;
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
line-height: 50px;
padding: 0 10px;
}
nav .nav-actions li {
font-size: 12px;
color: #8f8e8c;
line-height: 20px;
}
var nav = {
elem: $('nav'),
state: 'fixed',
offsetLimit: $('nav .nav-actions').outerHeight(),
currentOffsetAmount: 0,
scrollThreshold: 50,
init: function() {
var oldScrollTop = 0;
var thresholdCounter = 0;
$(window).on('scroll', function() {
var newScrollTop = $(document).scrollTop();
var delta = oldScrollTop - newScrollTop;
thresholdCounter = Math.min(Math.max(thresholdCounter + delta, -nav.scrollThreshold), nav.scrollThreshold);
var newOffset;
if (Math.abs(thresholdCounter) >= nav.scrollThreshold || nav.state == 'scrolling') {
if (delta < 0 && nav.state !== 'hidden') {
if (nav.currentOffsetAmount > -nav.offsetLimit) {
nav.currentOffsetAmount = Math.max(nav.currentOffsetAmount + delta, -nav.offsetLimit);
nav.elem.css('top', nav.currentOffsetAmount);
nav.state = 'scrolling';
} else {
nav.state = 'hidden';
thresholdCounter = 0;
}
} else if (delta > 0 && nav.state !== 'fixed') {
if (nav.currentOffsetAmount < 0) {
nav.currentOffsetAmount = Math.min(nav.currentOffsetAmount + delta, 0);
nav.elem.css('top', nav.currentOffsetAmount);
nav.state = 'scrolling';
} else {
nav.state = 'fixed';
thresholdCounter = 0;
}
}
}
oldScrollTop = newScrollTop;
});
}
};
nav.init();
Also see: Tab Triggers