css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console