Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                <header>
	<p>Hamburger</p>
	<nav>
		<button aria-controls="nav-collapsible" hidden="">Menu</button>
		<div id="nav-collapsible">
			<ul>
				<li><a href="">Hamburg-Mitte</a></li>
				<li><a href="">Altona</a></li>
				<li><a href="">Eimsbüttel</a></li>
				<li><a href="">Hamburg-Nord</a></li>
				<li><a href="">Wandsbek</a></li>
				<li><a href="">Bergedorf</a></li>
				<li><a href="">Harburg</a></li>
			</ul>
		</div>
	</nav>
</header>
<main id="main">
	<p>Claudius Ptolemy (2nd century AD) reported the first name for the vicinity as Treva.</p>
	<p>The name Hamburg comes from the first permanent building on the site, a castle which the Emperor Charlemagne ordered constructed in AD 808. It rose on rocky terrain in a marsh between the River Alster and the River Elbe as a defence against Slavic incursion, and acquired the name Hammaburg, burg meaning castle or fort. The origin of the Hamma term remains uncertain, as does the exact location of the castle.</p>
	<footer>(Source: Wikipedia)</footer>
</main>

              
            
!

CSS

              
                * { box-sizing: border-box }

html
{
	background: black;
}

body
{
	margin: auto;
	max-width: 24em;
	min-height: 100vh;
	background: white;
	position: relative;
	font-family: Source Sans Pro, Open Sans, Calibri, sans-serif;
}

header
{
	padding: 1em;
	display: flex;
	flex-flow: row wrap;
	justify-content: space-between;
	align-items: center;
	background: #da121a;
	color: white;
}

button[aria-controls="nav-collapsible"]
{
	font: inherit;
	color: currentcolor;
	border: thin solid;
	border-radius: 0.25em;
	padding: 0.5em 2em;
	background: transparent url(https://upload.wikimedia.org/wikipedia/commons/5/5d/DEU_Hamburg_COA.svg) 0.5em center / auto 80% no-repeat;
	position: relative;
}

button[aria-controls="nav-collapsible"]::after
{
	content: '▶︎';
	position: absolute;
	right: 1em;
	bottom: 0.9em;
	font-size: 0.7em;
}

button[aria-controls="nav-collapsible"][aria-expanded="true"]::after
{
	content: '▼'
}

#nav-collapsible
{
	position: absolute;
	top: var(--page-header-height);
	right: 0;
	bottom: 0;
	left: 0;
	background: hsl(0deg 0% 95%);
	color: black;
	transition: 0.1s transform ease-in-out;
	transform-origin: right;
}

#nav-collapsible[hidden]
{
	display: block !important;
	transform: scaleX(0);
}

nav ul
{
	list-style: none;
  list-style: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'/%3E"); /* Safari hack, see https://www.scottohara.me/blog/2019/01/12/lists-and-safari.html */
	margin: 0;
	padding: 0;
}

nav li:not(:last-child)
{
	border-bottom: thin solid silver;
}

nav a
{
	display: block;
	padding: 0.5em 1em;
	color: currentcolor;
	text-decoration: none;
}

:focus
{
	background-color: black !important;
	color: white !important;
}

main
{
	padding: 1em;
	max-width: 42em;
}


              
            
!

JS

              
                const collapsibleElement = document.querySelector('#nav-collapsible');
collapsibleElement.controlElement = document.querySelector('[aria-controls="nav-collapsible"]');

collapsibleElement.toggle = (event, force) => {
	const isToBeVisible = force !== undefined ? force : collapsibleElement.hidden;
	collapsibleElement.hidden = !isToBeVisible;
	collapsibleElement.setAttribute('aria-hidden', !isToBeVisible);
	collapsibleElement.controlElement.setAttribute('aria-expanded', isToBeVisible);
	if (!isToBeVisible)
	{
		//collapsibleElement.controlElement.focus();
	}
}

collapsibleElement.close = event => collapsibleElement.toggle(event, false);
collapsibleElement.open = event => collapsibleElement.toggle(event, true);

collapsibleElement.close();

collapsibleElement.controlElement.hidden = false;

collapsibleElement.controlElement.addEventListener('click', collapsibleElement.toggle);

document.documentElement.addEventListener('click', event => {
	if (event.target !== collapsibleElement.controlElement && !event.target.closest('#nav-collapsible'))
	{
		collapsibleElement.close();
	}
});

document.documentElement.addEventListener('keyup', event => {
	if (event.code === 'Escape')
	{
		collapsibleElement.close();
		collapsibleElement.controlElement.focus();
	}
});

const pageHeaderElement = document.querySelector('header');
	
pageHeaderElement.setHeightCustomProperty = () => {
	if (window.CSS && CSS.supports && CSS.supports('--page-header-height: 0'))
	{
		pageHeaderElement.style.setProperty('--page-header-height', `${pageHeaderElement.offsetHeight}px`);
	}
	else
	{
		document.querySelector('#nav-collapsible').style.setProperty('top', `${pageHeaderElement.offsetHeight}px`);
	}
};

window.addEventListener('load', pageHeaderElement.setHeightCustomProperty);
window.addEventListener('resize', pageHeaderElement.setHeightCustomProperty);
              
            
!
999px

Console