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 URL's 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 it's URL and the proper URL extention.
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.
<div class="wrap">
<h1 class="pen-title">Simple Sticky Navigation Bar</h1>
<p class="pen-description">A navigation bar that sticks to the top of the screen when scrolling.</p>
<!-- Begin Your Code -->
<nav class="navigation-menu">
<ul class="menu">
<li><a href="http://www.webdevstudios.com">WebDevStudios</a></li>
<li class="menu-item-has-children"><a href="https://apppresser.com/">AppPresser</a>
<ul class="menu sub-menu">
<li><a href="#">Submenu Item 1</a></li>
<li class="menu-item-has-children"><a href="#">Submenu Item 3</a>
<ul class="menu sub-menu">
<li><a href="#">Submenu Item 1</a></li>
<li class="menu-item-has-children"><a href="#">Submenu Item 3</a>
<ul class="menu sub-menu">
<li><a href="#">Submenu Item 1</a></li>
<li><a href="#">Submenu Item 3</a></li>
<li><a href="#">Submenu Item 3</a></li>
</ul>
</li>
<li><a href="#">Submenu Item 3</a></li>
</ul>
</li>
<li><a href="#">Submenu Item 3</a></li>
</ul>
</li>
<li><a href="https://maintainn.com/">Maintainn</a></li>
<li class="menu-item-has-children"><a href="https://tinyurl.com/gtg98bs">Who is the best?</a>
<ul class="menu sub-menu">
<li><a href="#">Submenu Item 1</a></li>
<li class="menu-item-has-children"><a href="#">Submenu Item 3</a>
<ul class="menu sub-menu">
<li><a href="#">Submenu Item 1</a></li>
<li class="menu-item-has-children"><a href="#">Submenu Item 3</a>
<ul class="menu sub-menu">
<li><a href="#">Submenu Item 1</a></li>
<li><a href="#">Submenu Item 3</a></li>
<li><a href="#">Submenu Item 3</a></li>
</ul>
</li>
<li><a href="#">Submenu Item 3</a></li>
</ul>
</li>
<li><a href="#">Submenu Item 3</a></li>
</ul>
</li>
</ul>
</nav>
<div id="content" class="site-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vestibulum ligula est, non tempor lectus dapibus non. Proin nec eleifend sapien. Fusce diam urna, ultrices vitae imperdiet at, varius sit amet metus. Integer eu risus ullamcorper, porta augue vitae, sollicitudin tellus. Vestibulum nec metus ultricies, hendrerit metus in, fringilla justo. Vestibulum consequat purus ut libero fringilla accumsan. Sed mattis pharetra metus faucibus pharetra.</p>
<p>Aliquam sit amet felis in magna interdum auctor. Donec eros augue, semper at sapien non, facilisis congue odio. Nunc ac elit aliquam, convallis leo in, finibus ipsum. Aenean neque metus, aliquam eget finibus a, tristique sed tellus. Sed elementum mattis justo, ac condimentum lacus condimentum lobortis. Sed venenatis eros venenatis risus maximus, ut porta quam semper. Aenean ex turpis, interdum vitae ornare nec, congue ut sem. Proin nec sem tortor. Praesent eu varius magna.</p>
<p>Vivamus tempor tortor ac nibh rhoncus sollicitudin. Aliquam id nibh mattis, rhoncus libero sit amet, viverra nisl. Cras eu cursus enim. Aliquam congue ex non pellentesque auctor. Sed tincidunt ullamcorper nisi, vel scelerisque lorem efficitur at. Nam cursus magna ac arcu porttitor tristique. Fusce molestie, neque a laoreet pellentesque, augue erat suscipit felis, sit amet varius dui enim a dui. Donec cursus libero et nisi ultricies lacinia. Curabitur elementum condimentum sem, in tempus neque aliquet ac. Morbi finibus finibus nisi eget auctor. Nam vulputate vestibulum elit quis consectetur.</p>
<p>Donec rutrum dolor at quam commodo, at vestibulum libero porttitor. Curabitur justo diam, malesuada a elementum vel, rhoncus sed lorem. In mauris sem, aliquet sit amet finibus at, egestas id enim. Fusce ex elit, vehicula nec nulla a, mollis auctor risus. Integer tristique tellus eu metus commodo, sed convallis ipsum mollis. In augue lectus, semper non leo sit amet, fringilla auctor elit. Aenean at dui sapien. Quisque aliquam nulla eget lacus consectetur, non ullamcorper ex aliquam. Aenean dictum elit eu turpis ornare, in mattis tortor feugiat. Duis pellentesque ipsum quis interdum rutrum. Sed at sem ut magna tristique pharetra. Praesent scelerisque malesuada massa eu cursus.</p>
<p>Mauris bibendum tortor et porttitor tincidunt. Mauris aliquet, ex quis cursus semper, nunc elit imperdiet ante, et condimentum ex est nec nunc. In eu velit ligula. Aliquam sed dapibus nibh. Proin vitae sapien in dui vestibulum fringilla. Vestibulum commodo tortor nulla. Sed cursus urna vitae lacus placerat, et vulputate sapien maximus. Nullam et leo non lorem sagittis ornare a ac nisi.</p>
<p>Sed eget lorem eget lorem pellentesque scelerisque porta quis justo. Mauris et nunc ac eros laoreet varius ut non urna. Mauris vitae dignissim nibh, sit amet feugiat lacus. In vitae elementum risus, nec condimentum felis. Sed porttitor, elit et vulputate consequat, leo augue pellentesque libero, eu auctor nisi nulla at leo. Phasellus diam felis, malesuada rutrum malesuada vitae, tempor non magna. Maecenas mollis nisl at pharetra sagittis. Aliquam erat volutpat. Fusce mi tortor, ullamcorper nec libero pretium, commodo consequat eros. Sed pellentesque eleifend auctor. Donec vel lobortis enim. Integer ut ullamcorper mauris. Fusce mi mauris, laoreet ut auctor at, placerat sit amet turpis. Cras tempus magna at est ultrices dignissim. Sed a ullamcorper erat.</p>
<p>Pellentesque nec mauris a turpis cursus scelerisque. Pellentesque lectus erat, luctus quis sapien ac, pulvinar lacinia eros. Pellentesque elementum massa id sem mattis, ac pharetra urna ultricies. Vestibulum sagittis, lacus at viverra tincidunt, tellus velit porttitor dolor, scelerisque viverra felis dolor sit amet neque. Donec sit amet nisi id libero suscipit varius nec et lacus. Aenean hendrerit sit amet arcu fringilla egestas. Etiam lobortis justo odio, non gravida ligula consectetur vel. In ac enim eu ante efficitur vulputate. Mauris pharetra venenatis vestibulum. Mauris imperdiet ac leo sit amet auctor. Nulla in sem lacus. Sed volutpat, lectus sed scelerisque efficitur, erat massa lacinia nulla, ac tincidunt nunc mauris ut tellus. In at blandit dolor.</p>
<p>Quisque massa diam, scelerisque in scelerisque et, pellentesque ac risus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Duis commodo quis nisi commodo pharetra. In mollis nec tortor in congue. Aenean lobortis porta odio, vitae pretium felis. Sed efficitur lorem at felis pulvinar vehicula. Quisque imperdiet massa a tellus aliquet, quis viverra turpis dignissim. Curabitur facilisis semper aliquet. Donec tempus, ex sit amet tincidunt pretium, nibh lectus auctor lorem, a fringilla libero enim vel neque. Pellentesque vel mi a odio tincidunt finibus.</p>
<p>Sed scelerisque risus quam, sit amet malesuada odio dignissim nec. Phasellus dolor odio, imperdiet sed lectus vel, sagittis ornare mauris. Praesent maximus est mollis imperdiet pulvinar. Ut tempus ex vel scelerisque venenatis. Etiam in urna porta, varius risus sed, ornare diam. Duis aliquam molestie augue, a consectetur mi. Etiam et iaculis purus, dapibus volutpat metus. Nam lacus magna, vehicula vitae molestie sed, iaculis eget elit. Ut mi enim, mollis at sagittis vitae, semper sed odio. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu iaculis augue.</p>
<p>Integer tincidunt orci vitae arcu ornare, sit amet lobortis lectus consequat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc tincidunt odio eu neque imperdiet lobortis. Etiam blandit scelerisque diam vitae vehicula. Ut accumsan risus ut condimentum iaculis. Integer at auctor erat. Nullam urna augue, interdum eu augue rhoncus, lobortis pulvinar mi. Sed venenatis dui at ipsum consequat auctor. Nunc ligula nulla, rhoncus ac massa in, finibus rutrum libero. Vivamus a cursus enim.</p>
</div>
<!-- End Your Code -->
</div><!-- .wrap -->
p {
color: $color-white;
}
// Setup our nav menu styles
.navigation-menu {
max-width: rem(1366);
width: 100%;
// We add a sticky-nav class to the body, so adjust styles based on that class
.sticky-nav & {
position: fixed;
top: 0;
}
}
// Add padding to the top of site content so nothing jumps when the bar becomes sticky. Height is equal to the nav bar height.
.site-content {
.sticky-nav & {
padding-top: rem(52);
}
}
/**
* Simple Sticky Navigation Bar
*/
window.WDS_Sticky_Navigation = {};
( function( window, $, that ) {
// Constructor.
that.init = function() {
that.cache();
if ( that.meetsRequirements ) {
that.bindEvents();
}
};
// Cache all the things.
that.cache = function() {
that.$c = {
window: $( window ),
body: $( 'body' ),
navBar: $( '.navigation-menu' ),
navBarTop: $( '.navigation-menu' ).offset().top
};
};
// Combine all events.
that.bindEvents = function() {
that.$c.window.on( 'scroll', that.stickNavToTop );
};
// Do we meet the requirements?
that.meetsRequirements = function() {
return that.$c.navBar.length;
};
// Stick nav to top.
that.stickNavToTop = function() {
// Find our window scroll position
var scrollPosition = that.$c.window.scrollTop();
// If we scroll to or beyond the top of our nav bar, stick it to the top of the window
if ( scrollPosition >= that.$c.navBarTop ) {
that.$c.body.addClass( 'sticky-nav' );
} else {
that.$c.body.removeClass( 'sticky-nav' );
}
};
// Engage!
$( that.init );
})( window, jQuery, window.WDS_Sticky_Navigation );
Also see: Tab Triggers