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.
<div class="positioner">
<div class="menu">
<div class="menu_title">
Fancy Icon Menu
</div>
<div class="menu_item">
<input class="toggle" name="menu_group" id="sneaky_toggle" type="radio">
<div class="expander">
<label for="sneaky_toggle"><i class="menu_icon fa fa-bomb"></i> <span class="menu_text">Da Bomb</span></label>
</div>
</div>
<div class="menu_item">
<input class="toggle" name="menu_group" id="sneaky_toggle2" type="radio">
<div class="expander">
<label for="sneaky_toggle2"><i class="menu_icon fa fa-bell"></i> <span class="menu_text">Da Bell</span></label>
</div>
</div>
<div class="menu_item">
<input class="toggle" name="menu_group" id="sneaky_toggle3" type="radio">
<div class="expander">
<label for="sneaky_toggle3"><i class="menu_icon fa fa-child"></i> <span class="menu_text">Da Kid</span></label>
</div>
</div>
</div>
</div>
<div class="positioner">
<div class="menu">
<div class="menu_title">
Fancy Icon Menu
</div>
<div class="menu_item">
<input class="toggle" name="menu_group2" id="sneaky_togglea" type="checkbox">
<div class="expander">
<label for="sneaky_togglea"><i class="menu_icon fa fa-bomb"></i> <span class="menu_text">Da Bomb</span></label>
</div>
</div>
<div class="menu_item">
<input class="toggle" name="menu_group2" id="sneaky_toggleb" type="checkbox">
<div class="expander">
<label for="sneaky_toggleb"><i class="menu_icon fa fa-bell"></i> <span class="menu_text">Da Bell</span></label>
</div>
</div>
<div class="menu_item">
<input class="toggle" name="menu_group2" id="sneaky_togglec" type="checkbox">
<div class="expander">
<label for="sneaky_togglec"><i class="menu_icon fa fa-child"></i> <span class="menu_text">Da Kid</span></label>
</div>
</div>
</div>
</div>
// Includes
@import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css');
// Variables
$icon_size: 3rem; // 32px @ 16px default rem size
$icon_color: #ccc;
$icon_color_hover: #fff;
$icon_color_checked: #ABDC38;
$max_expansion: 16rem; // 16*16 = 256px => max width of expansion, directly relates to the transition timing length
$menu_text_size: 1.5rem; // size of the menu text
$menu_text_color: #fff;
$menu_bg: #333;
$menu_item_padding: 1.5rem;
$menu_item_bg: none;
$menu_item_bg_hover: #000;
$menu_item_bg_checked: #222;
$menu_border_radius: $icon_size/4;
.menu {
font-family: arial;
background: $menu_bg;
//font-size: 0.0001rem; // fix for inline-block spacing "glitch"
//overflow: hidden;
display: table;
position: relative;
margin: 0 $menu_border_radius;
box-shadow: 0 $icon_size/1.5 $icon_size*3 rgba(0,0,0,0.8);
&:before, &:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
width: $menu_border_radius;
background: $menu_bg;
}
&:before {
left: -$menu_border_radius;
border-radius: $menu_border_radius 0 0 $menu_border_radius;
}
&:after {
right: -$menu_border_radius;
border-radius: 0 $menu_border_radius $menu_border_radius 0;
}
}
.menu_item {
display: block;
float: left;
white-space: nowrap;
color: $icon_color;
font-size: $menu_text_size;
//margin-right: 0.5rem;
&:last-child {
margin-right: 0;
}
.toggle {
display: none;
&:checked ~ {
& .expander {
max-width: $max_expansion;
background: $menu_item_bg_checked;
.menu_icon {
color: $icon_color_checked;
animation: none;
}
.menu_text {
color: $menu_text_color;
}
}
}
}
.expander {
max-width: $icon_size;
overflow: hidden;
transition: all ease-in-out 233ms;
padding: $menu_item_padding;
padding-right: $menu_item_padding;
&:hover {
background: $menu_item_bg_hover;
.menu_icon {
color: $icon_color_hover;
animation: jiggle ease-in-out 400ms infinite;
}
}
}
label {
line-height: $icon_size;
}
.menu_icon {
display: inline-block;
font-size: $icon_size;
line-height: $icon_size;
vertical-align: middle;
width: $icon_size;
text-align: center;
margin-right: 0.5rem;
transition: color ease-in-out 80ms;
}
.menu_text {
line-height: $icon_size;
color: transparent;
display: inline-block;
vertical-align: middle;
padding-right: $menu_item_padding;
transition: color ease-out 333ms;
}
}
.menu_title {
color: $menu_text_color;
font-size: $menu_text_size;
display: block;
float: left;
line-height: $icon_size;
padding: $menu_item_padding;
}
.positioner {
display: table;
margin: 0 auto;
margin-top: calc(50vh - #{$icon_size + $menu_item_padding/2})
}
@keyframes jiggle {
0% {
transform: none;
}
25% {
transform: rotateZ(5deg);;
}
75% {
transform: rotateZ(-5deg)
}
100% {
transform: none;
}
}
// This box must be useful for something... how about some extra comments?
// This is a css only solution to an expanding menu
// It uses radio buttons and...
// These standard CSS "tricks"
// the :checked css pseudo class
// max-width transition effect
// Block, float:left is used for menu items, so they'll display inline and react to each other's widths
// Line-height and vertical align is used to ensure that the icons/text and things stay lined up.
// * Vertical align works in this case because inline-block elements are next to each other.
// * They vertically align with themselves and not the parent.
/*
The icons are font awesome icons
https://fortawesome.github.io/Font-Awesome/
*/
/*
The html structure goes like this
div.menu {
div.menu_item {
input.toggle {
}
.expander {
label {
i.menu_icon {}
span.menu_text {}
}
}
}
}
*/
// How it all comes together
//
// 1.) By default the max-width of the expander is set to the icon size plus a little extra for padding.
// 2.) The expander overflow is set to hidden
// 3.) Fun fact. Labels work to toggle check boxes too. So we hide the check box itself.
// 4.) In the html we set the name of each radio button the same, so they interact with each other when clicked
// 5.) Give each radio a unique ID
// 6.) Using CSS, we then create a property that selects elements next to the input.toggle element
// When it is checked.
// 7.) Using this selector we set the max-width of the .expander and give it a transition property of all. For fun I added a background change as well.
// * Max-width will allow us to use a dynamic width to transition to with CSS. But it needs a maxiumum value. I set an arbitrary width of 16rem.
// If this is increased, the timing of the transition CSS property will need to be adjusted since it uses the max value to set the speed
// * That should get the boxes expanding and closing on click.
// 8.) To make it look like a menu. I wrapped each .menu_item with another div and gave it some background.
// 9.) There is also an issue of wrapping text. To make the button text not wrap apply the white-space: nowrap; property to the menu_item.
// 10.) From there, it's all just stylistic adjustments
Also see: Tab Triggers