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

              
                <nav class="focus-within-variant">
	<ul>
		<li><a href="">Vorspeise</a></li>
		<li>
			<a href="">Hauptgericht</a>
			<ul>
				<li><a href="">Hauptgericht mit&nbsp;Fleisch</a></li>
				<li><a href="">Hauptgericht vegetarisch</a></li>
			</ul>
		</li>
		<li><a href="">Dessert</a></li>
	</ul>
</nav>
<p>Dieses Menü wurde ohne JavaScript zubereitet. Als Zutat wurde <code>:focus-within</code> verwendet; Gäste mit <s>Edge oder gar</s> Internet Explorer schauen also in die Röhre.</p>
<p>Das Menü ist für JS-Allergiker geeignet; es schmeckt bloß nicht. Vom Hauptgericht kommt man nicht zum Dessert, sondern man muss das Untermenü über sich ergehen lassen.</p>
<p>Das Menü ist nicht für kleine Tische geeignet. Wenn es nicht in eine Zeile passt, kommt man vom Hauptgericht nicht ins Untermenü.</p>

<nav class="focus-within-variant">
	<ul>
		<li><a href="">Vorspeise</a></li>
		<li tabindex="0">
			Hauptgericht
			<ul>
				<li><a href="">Hauptgericht mit&nbsp;Fleisch</a></li>
				<li><a href="">Hauptgericht vegetarisch</a></li>
			</ul>
		</li>
		<li><a href="">Dessert</a></li>
	</ul>
</nav>
<p>Im Unterschied zu oben ist das Hauptgericht hier kein Link. Damit das Menü tastaturbedienbar ist, trägt das <code>li</code>-Element das Attribut <code>tabindex="0"</code>. Ansonsten gilt das oben Gesagte.</p>
<p>Mit JavaScript könnte man noch dafür sorgen, dass beim Aufklappen des Untermenüs der erste Untermenüpunkt den Fokus erhält. Aber wenn schon JavaScript, dann kann man’s auch gleich richtig machen …</p>

<nav class="button-variant">
	<ul>
		<li><a href="">Vorspeise</a></li>
		<li>
			<button aria-expanded="false">Hauptgericht</button>
			<ul>
				<li><a href="">Hauptgericht mit&nbsp;Fleisch</a></li>
				<li><a href="">Hauptgericht vegetarisch</a></li>
			</ul>
		</li>
		<li><a href="">Dessert</a></li>
	</ul>
</nav>
<p>Das Hauptgericht ist hier ein Button (<code>&lt;button&gt;</code>), der per JavaScript die Sichtbarkeit des Untermenüs steuert – über das <code>aria-expanded</code>-Attribut zur barrierefreien Bedienung.

<nav class="button-variant">
	<ul>
		<li><a href="">Vorspeise</a></li>
		<li>
			<a href="">Hauptgericht</a>
			<button aria-expanded="false">
				<span visually-hidden="true">Untermenü Hauptgericht</span>
			</button>
			<ul>
				<li><a href="">Hauptgericht mit&nbsp;Fleisch</a></li>
				<li><a href="">Hauptgericht vegetarisch</a></li>
			</ul>
		</li>
		<li><a href="">Dessert</a></li>
	</ul>
</nav>
<p>Hier ist das Hauptgericht wieder ein Link. Es sind zwei getrennte UI-Elemente: der Link und der Button zum Öffnen/Schließen des Untermenüs.</p>
<p>Bei den unteren Menüs fehlen noch Zutaten:</p>
<ul>
	<li>Das Untermenü sollte sich beim Verlassen schließen.</li>
	<li>Das Untermenü sollte sich per Esc-Taste schließen.</li>
</ul>
<p>(Die Liste erhebt keinen Anspruch auf Vollständigkeit.)</p>
              
            
!

CSS

              
                body
{
	margin: 0;
	padding-bottom: 4em;
	font-family: Calibri, sans-serif;
	line-height: 1.5;
}

nav
{
	--background-color: hsl(-10deg 80% 40%);
	--text-color: white;
	background-color: var(--background-color);
	color: var(--text-color);
	box-shadow: 0 0.1em 0.1em black;
	font-family:  Didot, serif;
	font-size: 1.25em;
	line-height: 1.25;
}

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

nav ul ul
{
	display: none;
	position: absolute;
	left: 0;
	top: 100%;
	background-color: var(--background-color);
	box-shadow: 0 0.1em 0.1em 0em black;
	z-index: 1;
	font-size: 0.9em;
}

nav.focus-within-variant li:focus-within ul
{
	display: block;
}

nav [aria-expanded="true"] + ul
{
	display: block;
}

nav li:hover ul
{
	display: block;
}

[aria-expanded]
{
	padding-right: 2em;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'%3E%3Cpath d='M0.3,0.1 0.3,0.9 0.8,0.5z' fill='white'/%3E%3C/svg%3E");
	background-position: right 1em center;
	background-size: 0.8em 0.8em;
	background-repeat: no-repeat;
}

[aria-expanded="true"]
{
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1 1'%3E%3Cpath d='M0.1,0.3 0.9,0.3 0.5,0.8z' fill='white'/%3E%3C/svg%3E");
}

nav li
{
	padding: 0.25em 1em;
	position: relative;
}

nav a,
nav button
{
	display: inline-block;
	color: currentColor;
	text-decoration: none;
	margin: -0.25em -1em;
	padding: 0.25em 1em;
}

nav button
{
	background-color: transparent;
	background-color: var(--background-color);
	border: none;
	font: inherit;
}

nav a + button
{
	margin-left: 0;
	padding-left: 0;
	width: 1em;
	height: 1.75em;
	vertical-align: text-top;
}

nav a:hover
{
	background-color: hsl(-10deg 75% 50%);
}

nav a:focus,
nav button:focus
{
	background-color: black;
	outline: none;
}

:is(p, ul)
{
	margin: 1em 1em 4em;
	max-width: 36em;
}

:is(p, ul) + :is(p, ul)
{
	margin-top: -4em;
}

code
{
	font-family: Fira Mono, monospace;
}

visually-hidden,
.visually-hidden,
[visually-hidden="true"]
{
	position: absolute !important;
	clip: rect(1px, 1px, 1px, 1px) !important;
	padding: 0 !important;
	border: 0 !important;
	height: 1px !important;
	width: 1px !important;
	overflow: hidden !important;
}

              
            
!

JS

              
                document.documentElement.addEventListener('click', event => {
	if (event.target.tagName == 'BUTTON' && event.target.hasAttribute('aria-expanded'))
	{
		event.target.setAttribute('aria-expanded', event.target.getAttribute('aria-expanded') != 'true');
	}
});

document.documentElement.lang = 'de';


              
            
!
999px

Console