Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- 
Change the class string "logged-in" below to see the style adapt
-->
<div class="logged-in">
	<div class="fake-wp-admin-bar">Fake WP Admin Bar</div>
	<nav class="menu-bar">Lots of great menu items would be here.</nav>
	<div class="main-content">
		<h1>Such great content here</h1>
		<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Dolores asperiores dicta dolorem qui unde cumque. Vero fugiat voluptatum deleniti commodi dolor officia qui, libero modi velit veniam maxime at esse!</p>
		<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Dolores asperiores dicta dolorem qui unde cumque. Vero fugiat voluptatum deleniti commodi dolor officia qui, libero modi velit veniam maxime at esse!</p>
		<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Dolores asperiores dicta dolorem qui unde cumque. Vero fugiat voluptatum deleniti commodi dolor officia qui, libero modi velit veniam maxime at esse!</p>
	<div class="add-height"></div>
	</div>
</div>
	
              
            
!

CSS

              
                :root {
	// 1. Set up the constant values
	// It's best practice to keep custom property values unit-less, lest you run into issues I don't understand well enough to explain here.
	--login-bar-height: 0;
	--menu-bar-height: 50;
}

// 2. Conditionally adjust the height of the login bar based on WordPress' values.
// if body has class "logged-in" and screen is > 783px, update the value.
.logged-in { // This class is added to <body> by WordPress
	@media ( min-width: 783px ) { // Breakpoint comes from WordPress
		--login-bar-height: 32;
	}
}

// 3. Bind the custom property values to regular properties.
// When the login bar isn't here, the value of the --login-bar-height 
// property will be 0 because of our conditional above. 
// So satisfying and clean and great!!!
// Is CSS a programming language?
.menu-bar {
	// Fix the menu bar. This would also work for an absolutely positioned bar.
	width: 100%;
	position: fixed;
	
	// Use calc to apply a unit to the custom property value
	top: calc( var( --login-bar-height ) * 1px ); 
	height: calc( var( --menu-bar-height ) * 1px );
}

.main-content {
	// Pad the top of the content to account for both the menu and login bar height.
	padding-top: calc( ( var( --menu-bar-height ) + var( --login-bar-height ) ) * 1px );
}









// Not part of the algorithm

.stuff {
	height: 1000px;
}

.menu-bar {
	background-color: skyblue;
	display: flex;
	align-items: center;
	justify-content: center;
}

.fake-wp-admin-bar {
	display: none;
	height: 32px;
	z-index: 100;
	color: white;
	background-color: #666;
	top: 0;
	left: 0;
	position: relative;
	width: 100%;
	
	.logged-in & {
		display: block;
	}
	
	@media ( min-width: 783px ) {
		position: fixed;
	}
}

.add-height {
	height: 1000px;
	background: peachpuff;
}

              
            
!

JS

              
                
              
            
!
999px

Console