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

              
                <nav class="navbar">
	<details class="bad">
		<summary>
			Best Foods (BROKEN mousover experience) 👎
		</summary>
		<div class="dropdown-wrapper">
			<ul>
				<li><a href="#">Shephard's Pie</a></li>
				<li><a href="#">Empanadas</a></li>
				<li><a href="#">Pound Cakes</a></li>
				<li><a href="#">Tacos</a></li>
				<li><a href="#">ALL OTHER PIES</a></ul>
		</div>
	</details>
</nav>
<br><br>
<nav class="navbar">
	<details class="good">
		<summary>
			Best Foods - FIXED Mouseover experience 👍
		</summary>
		<div class="dropdown-wrapper">
			<ul>
				<li><a href="#">Shephard's Pie</a></li>
				<li><a href="#">Empanadas</a></li>
				<li><a href="#">Pound Cakes</a></li>
				<li><a href="#">Tacos</a></li>
				<li><a href="#">ALL OTHER PIES</a></ul>
		</div>
	</details>
</nav>
<br>
<p>
	The broken menu above opens just fine because there's a mouseover event triggered on the summary element. But in this scenario, that summary has a set height and doesn't expand to the height of its other content when in the "open" state. So clicking on a link in the broken menu isn't possible, except by fluke.
</p>
<p>
	On the "fixed" menu at the bottom, the height of the summary element is still hard-coded, but the gap between the summary element and the "dropdown-wrapper" div is covered by an invisible <code>.dropdown-wrapper::before</code> pseudo-element. This means that as the user moves the pointer down, it's always over a "child" of the orginal summary element, and so never triggers a "mouseleave" on that element.</p>

<p>
	There's one other pseudo-element in use here, to create the little triangle pointing up to the menu trigger.
</p>
              
            
!

CSS

              
                
body {
	min-height: 600px;
}
summary::-webkit-details-marker {
	display: none;
}

p, .navbar {
	max-width: 400px;
	margin: 20px auto;
}

summary {
	cursor: default;
	background-color: white;
	outline: 1px solid green;
	padding: 2px;
}


summary:focus {
	background-color: lightblue
}
.dropdown-wrapper {
	background-color: lightblue;
	position: relative;
	z-index: 10;
}

.dropdown-wrapper::before {
	position: absolute;
	content: "";
	background-color: inherit;
	height: 12px;
	width: 12px;
	top: -5px;
	left: 8px;
	transform: rotate(45deg);
}

details.bad,
details.good{
	/* Fixed height! This will mean both "bad" and "good" menues have broken mouseover experiences */
	height: 18px;
/* But sometimes designs call for stuff like this, or you are adding functionality to an exsiting structure and there's not time to rewrite all the surrounding code to accommodate the change*/
}

details.bad summary {
	outline: 1px solid red;
}
details.good {
	position: relative;
}

details.good::before {
	content:"";
	width: 100%;
	height: 40px;
	position: absolute;
	bottom:-48px;
}

details[open] .dropdown-wrapper {
	animation: fade-in 0.5s forwards;
}

details.summary-closing[open] .dropdown-wrapper {
	animation: fade-out 0.5s forwards;
}

@keyframes fade-in {
	0% {
		transform: translateY(-20px);
		opacity: 0;
	}
	100% {
		transform: translateY(0);
		opacity: 1;
	}
}

@keyframes fade-out {
	0% {
		opacity: 1;
	}
	100% {
		opacity: 0;
		transform: translateY(-20px);
	}
}

              
            
!

JS

              
                let summaries = document.querySelectorAll("summary");

summaries.forEach(summary => {
	let details = summary.closest("details");
	console.log(summary, details)
	summary.addEventListener("click", function(event) {
		console.log(event)
		// first a guard clause: don't do anything
		// if we're already in the middle of closing the menu.
		if (details.classList.contains("summary-closing")) {
			return;
		}
		// but, if the menu is open ...
		if (details.open) {
			// prevent default to avoid immediate removal of "open" attribute
			event.preventDefault();
			// add a CSS class that contains the animating-out code
			details.classList.add("summary-closing");
			// when enough time has passed (in this case, 500 milliseconds),
			// remove both the "open" attribute, and the "summary-closing" CSS
			setTimeout(function() {
				details.removeAttribute("open");
				details.classList.remove("summary-closing");
			}, 500);
		}
	});
	// when user hovers over the summary element,
	// add the open attribute to the details element
	summary.addEventListener("mouseenter", event => {
		details.setAttribute("open", "open");
	});

	// when the user moves the mouse away from the details element,
	// perform the out-animation and delayed attribute-removal
	// just like in the click handler
	details.addEventListener("mouseleave", event => {
		event.target.classList.add("summary-closing");
		setTimeout(function() {
			event.target.removeAttribute("open");
			event.target.classList.remove("summary-closing");
		}, 500);
		event.target.setAttribute("open", "open");
	});
});

              
            
!
999px

Console