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. 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.
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.
If the stylesheet 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 CSS 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.
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='page'>
<header class='header'>
<div class='menu-btn-container'>
<span class='menu-btn'>Menu</span>
</div>
<nav class='main-menu'>
<ul class='menu'>
<li><a href='#'>Home</a></li>
<li><a href='#'>Team</a></li>
<li><a href='#'>Services</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Contact</a></li>
</ul>
<span class='menu-close-btn'>×</span>
</nav>
<div class='overlay'></div>
</header>
<div class='main'>
<div class='main-content'>
<h1>Pullout Menu with Overlay</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent congue ex id purus lobortis placerat. Etiam sed convallis ipsum. Cras mattis turpis nunc, non tempus leo rutrum vel. Ut quis pulvinar justo. Praesent ut suscipit odio. Nunc sodales, arcu vitae sagittis imperdiet, odio tellus volutpat urna, eu finibus mauris elit ac sem. Nam mattis dui quis mi porttitor sagittis. Cras a rhoncus erat. Phasellus quis ultricies justo. Nam ut ante et lectus pharetra venenatis. Praesent ullamcorper pretium facilisis.</p>
<p>Nunc et tellus tempus, cursus elit non, porttitor nibh. Nam imperdiet neque et pharetra laoreet. Praesent gravida libero sed libero malesuada porta. Duis a ipsum nec neque faucibus aliquet et id lectus. Phasellus vel condimentum magna. Nullam non metus justo. Cras vel arcu lectus. Suspendisse porttitor ipsum in enim interdum, in lacinia elit viverra. Phasellus vel neque tincidunt dui gravida ullamcorper at id erat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Quisque nec erat et urna viverra mollis. Curabitur aliquet velit quis massa porta ultrices.</p>
<p>Suspendisse orci est, tincidunt in leo ac, pellentesque laoreet sapien. Integer vehicula massa vel interdum posuere. Etiam mauris arcu, commodo non molestie id, porttitor ac risus. Aenean ac sem sit amet ligula egestas sollicitudin. Praesent id tristique velit. Phasellus sed nulla ac neque iaculis scelerisque. Donec elit lorem, efficitur suscipit neque vel, dictum luctus erat. In hendrerit accumsan est id ullamcorper. Fusce neque felis, faucibus et felis a, cursus cursus augue.</p>
</div>
</div>
</div>
/* Typography */
$fontFamily: Helvetica, Arial, sans-serif;
$rootFontSize: 16px;
$fontSize: 0.875rem;
$headerFontSize: 1.5rem;
/* Color */
$backgroundColor: #ffffff;
$menuBackgroundColor: rgba(#ffffff, 0.9);
$fontColor: #000000;
$linkFontColor: #5f5f5f;
$overlayColor: #000000;
/* Base Styles */
html {
font-size: $rootFontSize;
}
body {
font-family: $fontFamily;
font-size: $fontSize;
color: $fontColor;
background: $backgroundColor;
}
ul {
padding: 0;
margin: 0;
}
li {
list-style: none !important;
}
/* Header Styles */
.menu-btn {
cursor: pointer;
transition: 0.2s;
&:hover {
color: $linkFontColor;
}
}
/* Navigation Styles */
.main-menu {
position: fixed;
top: 0;
right: 100vw;
width: auto;
height: 100vh;
background: $menuBackgroundColor;
z-index: 20;
overflow: auto;
}
.menu {
padding: 1rem 5rem 0 1rem;
white-space: nowrap;
li {
padding-bottom: 1rem;
}
a {
display: block;
text-decoration: none;
transition: 0.2s;
&:link, &:visited {
color: $fontColor;
}
&:hover, &:active, &:focus {
text-decoration: none;
color: $linkFontColor;
}
}
}
.menu-close-btn {
position: absolute;
top: 0;
right: 0;
margin: 0.875rem 1rem 0 0;
cursor: pointer;
transition: 0.2s;
&:hover {
color: $linkFontColor;
}
}
/* Overlay Styles */
.overlay {
display: none;
position: fixed;
top: -20vh;
left: -20vw;
background: $overlayColor;
opacity: 0;
width: 140vw;
height: 140vh;
z-index: 10;
}
/* Page Styles */
h1 {
font-size: $headerFontSize;
text-align: center;
font-weight: normal;
}
jQuery(document).ready(function($) {
/* Variable declaration */
var mainMenu = $('.main-menu'),
menuBtn = $('.menu-btn'),
menuCloseBtn = $('.menu-close-btn'),
overlay = $('.overlay'),
windowVar = $(window),
slidePos,
slideTime = 400;
/* Functions for opening and closing menu */
function calcSlidePos(object) {
var objectWidth = object.outerWidth();
slidePos = (windowVar.width() - objectWidth) + "px";
}
function openMenu(menu) {
menu.animate({right: slidePos}, slideTime)
.removeClass("open close").addClass("open");
}
function closeMenu(menu) {
menu.animate({right: "100vw"}, slideTime)
.removeClass("open close").addClass("close");
}
/* Functions for overlay */
function overlayFadeIn(overlay) {
overlay.css({display: "block"}).animate({opacity: 0.85}, slideTime);
}
function overlayFadeOut(overlay) {
overlay.animate({opacity: 0}, slideTime, function() {
$(this).css({display: "none"});
});
}
/* Page JS */
menuBtn.click(function() {
calcSlidePos(mainMenu);
openMenu(mainMenu);
overlayFadeIn(overlay);
});
menuCloseBtn.click(function() {
closeMenu(mainMenu);
overlayFadeOut(overlay);
});
overlay.click(function() {
closeMenu(mainMenu);
overlayFadeOut(overlay);
});
});
Also see: Tab Triggers