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.
ul
li
a(href='#') Parent 1
li
a(href='#') _Child 1
li
a(href='#') _Another Child
li
a(href='#') _Child 3
li
a(href='#') __Granddhild 1
li
a(href='#') __Grandchild 2
li
a(href='#') _And A Longer Child
li
a(href='#') Parent 2
li
a(href='#') _First Child
li
a(href='#') _Second Child
li
a(href='#') Item 1
li
a(href='#') Parent 3
li
a(href='#') _Child 1
li
a(href='#') _Child 2
li
a(href='#') _Child 3
li
a(href='#') __Grandchild 1
li
a(href='#') __Grandchild 2
li
a(href='#') _Child 4
li
a(href='#') _Child 5
li
a(href='#') __Grandchild 1
li
a(href='#') __Grandchild 2
li
a(href='#') Item 2
li
a(href='#') Item 3
// SETTINGS
//---------------------------------------------------------
// Menu Collapse, change to something above viewport width to see responsive version
$toggle: 700px;
// Main Bar Background Color
$menu_bg: #B50A50;
// Link Color and Hover
$menu_color: white;
$item_hover_color: lighten($menu_bg, 75%);
// Drop Down Opener (Arrow Links)
$arrow_toggle_line: 1px solid rgba(white, .1);
$arrow_toggle_hover_bg: rgba(white, .1);
$arrow_toggle_color: white;
// Level Two Background and Background on hover
$level-two_bg: $menu_bg;
$level-two_hover_bg: rgba(white, .1);
// Level Three Background and Background on hover
$level-three_bg: $menu_bg;
$level-three_hover_bg: rgba(white, .1);
// Menu Text Alignment use[left, center, right]
$text_align: left;
// Responsive Toggle Link
$responsive_width: 100%;
$responsive_toggle_text_align: left;
$navtoggle_bg: #291018;
$navtoggle_color: white;
$navtoggle_hover_color: lighten(#291018, 80%);
// STYLES
//-----------------------------------------------------------------
// general styles
/* do not copy this, scroll further */
body{
line-height: 1.2;
background: #34364F;
font:{
family: 'Droid Sans', 'Calibri', 'Arial', sans-serif;
size: 16px;
}
}
.container{
width: 80%;
max-width: 1300px;
background: #F5F7F6;
margin: 80px auto;
padding: 30px;
box-sizing: border-box;
}
header{
padding: 80px 0;
}
p{
margin: 10px 0px;
}
h1{
font:{
size: 100px;
family: 'Old Standard';
}
color: #A62030;
text-transform: uppercase;
letter-spacing: 30px;
text-align: center;
}
a{
text-decoration: none;
transition: .3s all ease;
}
// Navigation
/* Copy Everything Below This Line */
.menu{
background: $menu_bg;
width: 100%;
padding: 3px 7px;
box-sizing: border-box;
text-align: $text_align;
position: fixed;
top: 0;
left: 0;
z-index: 10;
ul,
li{
margin: 0;
padding: 0;
}
// Basic Link styling
a{
color: $menu_color;
&:hover,
&:focus{
color: $item_hover_color;
}
}
// first level
> ul{
width: 100%;
position: relative;
display: inline-block;
li{
display: inline-block;
padding: 10px 7px;
}
}
// Drop Down Toggle Links
.fa{
border: $arrow_toggle_line;
border-radius: 2px;
padding: 3px 0px;
color: $arrow_toggle_color;
margin: 0 10px;
a{
font-size: 0;
padding: 0 !important;
}
&:hover,
&:focus{
background: $arrow_toggle_hover_bg;
cursor: pointer;
}
}
// Second Level
.level-two{
display: none;
position: absolute;
background: $level-two_bg;
top: 100%;
left: auto;
> li{
display: block;
background: transparent;
padding: 0;
transition: .3s all ease;
position: relative;
white-space: nowrap;
&:hover,
&:focus{
background: $level-two_hover_bg;
}
a{
width: 100%;
display: block;
padding: 10px 7px;
box-sizing: border-box;
}
}
// List Items with Sub Menus
.sharewidth{
> a{
display: inline-block;
width: auto;
}
}
}
.level-three{
display: none;
position: absolute;
left: 100%;
top: 0;
background: $level-three_bg;
li{
display: block;
background: transparent;
padding: 0;
transition: .3s all ease;
position: relative;
white-space: nowrap;
&:hover,
&:focus{
background: $level-three_hover_bg;
}
}
}
}
// Toggle Link
@media screen and (min-width: $toggle + 1){
.navtoggle{
display: none;
}
}
// Responsive Version
@media screen and (max-width: $toggle){
.outside{
position: fixed;
top: 0px;
left: 0px;
width: $responsive_width;
padding: 10px;
box-sizind: border-box;
text-align: $responsive_toggle_text_align;
z-index: 10;
background: $navtoggle_bg;
color: $navtoggle_color;
&:hover,
&:focus{
color: $navtoggle_hover_color;
cursor: pointer;
}
}
.menu{
position: fixed;
height: 100%;
top: 0;
left: -320px;
overflow-y: auto;
overflow-x: hidden;
transform: translate(0 0);
max-width: 320px;
transition: .3s all ease;
.navtoggle{
position: relative;
top: 0;
right: 0;
left: 0;
display: block;
text-align: right;
font-size: 0;
.fa{
font-size: 20px;
border: 0 solid transparent;
&:hover,
&:focus{
background: transparent;
opacity: .5;
}
}
}
&.active{
transform: translateX(320px);
transition: .3s all ease;
}
> ul li{
display: block;
}
.level-two,
.level-three{
position: relative;
left: 0;
top: 0;
}
}
}
$(function() {
// SETTINGS
//------------------------------------------------------
var one_level_list_element = $('ul'), // mandatory!
menu_name = 'Menu', // this will be used next to the hamburger icon for the toggle Button
menu_wrapper_class = 'menu',
parent_item_class = 'parent',
child_item_class = 'child-item',
grandchild_item_class = 'grandchild-item',
children_wrapper_class = 'level-two',
grandchildren_wrapper_class = 'level-three';
// DOM SETUP
//------------------------------------------------------
// locate children and grandchildren and store in variable
var grandchild = $('li a:contains("__")'),
child = $('li a:contains("_")');
// if list wrapper has no class add class nav, otherwise store class in variable
if (one_level_list_element.attr('class') == undefined) {
one_level_list_element.addClass('nav');
var ul_wrapper = 'nav';
} else {
var ul_wrapper = one_level_list_element.attr('class');
}
// Add class to child items
child.parent().addClass(child_item_class);
// wrap children in ul
var citem = $('.' + child_item_class);
for (var i = 0; i < citem.length;) {
i += citem.eq(i).nextUntil(':not(.' + child_item_class + ')').andSelf().wrapAll('<ul></ul>').length;
}
citem.parent().addClass(children_wrapper_class);
// add class to grandchildren
grandchild.parent().addClass(grandchild_item_class);
// wrap grandchildren in ul
var gitem = $('.' + grandchild_item_class);
for (var i = 0; i < gitem.length;) {
i += gitem.eq(i).nextUntil(':not(.' + grandchild_item_class + ')').andSelf().wrapAll('<ul></ul>').length;
}
gitem.parent().addClass(grandchildren_wrapper_class);
// add class to parents
$('.' + ul_wrapper + ' > li').addClass(parent_item_class);
// remove underscores from Names
$('.' + ul_wrapper + ' a').each(function() {
$(this).text($(this).text().replace(/_/g, ' '));
});
// append Grandchildren to Children
$('.' + children_wrapper_class + ' > .' + child_item_class).each(function() {
if ($(this).next().is('.' + grandchildren_wrapper_class)) {
$(this).next().appendTo($(this));
}
});
// append Children to parents
$('.' + ul_wrapper + ' > .' + parent_item_class).each(function() {
if ($(this).next().is('.' + children_wrapper_class)) {
$(this).next().appendTo($(this));
}
});
// wrap navigation in div container
$('.' + ul_wrapper).wrap('<div class="' + menu_wrapper_class + '"></div>');
// add toggle Links to open and close (uses Font-Awesome)
$('.' + menu_wrapper_class).before('<span class="navtoggle outside"><i class="fa fa-navicon"></i> ' + menu_name + '</span>');
$('.' + menu_wrapper_class).prepend('<span class="navtoggle"><i class="fa fa-close"></i></span>');
// add toggle open link for level one and two (uses FontAwesome again)
$('.' + children_wrapper_class).before('<i class="fa fa-fw fa-angle-down"></i>');
$('.' + grandchildren_wrapper_class).before('<i class="fa fa-fw fa-angle-right"></i>');
// now the basic HTML structure is created, we are ready to care about the menu functionality now
// MENU STUFF
//------------------------------------------------------
// Open function for parents
$('.fa-angle-down').click(function() {
if ($(this).siblings('.' + children_wrapper_class).is(':hidden')) {
$('.' + menu_wrapper_class + ' .' + children_wrapper_class).slideUp();
$(this).siblings('.' + children_wrapper_class).slideToggle();
} else {
$(this).siblings('.' + children_wrapper_class).slideUp();
}
});
// Open function for children
$('.fa-angle-right').click(function() {
if ($(this).siblings('.' + grandchildren_wrapper_class).is(':hidden')) {
$('.' + menu_wrapper_class + ' .' + grandchildren_wrapper_class).slideUp();
$(this).siblings('.' + grandchildren_wrapper_class).slideToggle();
} else {
$(this).siblings('.' + grandchildren_wrapper_class).slideUp();
}
});
// toggle active Class to open and close off-canvas Menu
// also change the angled icon's direction for children
$('.navtoggle').click(function() {
$('.' + menu_wrapper_class).toggleClass('active');
$('.' + children_wrapper_class + ' .fa').toggleClass('fa-angle-right, fa-angle-down');
});
// add class to child-item which has Grandchildren
// (so that toggle and link can be placed on one line)
if ($('li > .fa-angle-right').length > 0) {
$('li > .fa-angle-right').parent().addClass('sharewidth');
}
// grab the menu's height
var menuheight = $('.' + menu_wrapper_class).outerHeight();
// add this height as a margin to the body, so that the menu won't cover everything up.
$('body').css('margin-top', menuheight + 10)
});
Also see: Tab Triggers