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 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.

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 Edge oder gar 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>

<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>
              
            
!

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;
}

p
{
	margin: 1em 1em 4em;
	max-width: 36em;
}

p + p
{
	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