Technology News

Put a Background on Open Details Elements

One thing that can be just a smidge funky about the <details> element is that, when open, it’s not always 100% clear what is inside that element and what isn’t. I’m not saying that always matters or that it’s a particularly hard problem to solve, I’m just noting it as it came up recently for me.

Here’s a visual example:

A screenshot of some text with details elements present. One of them is open. It's not clear what text is within that details and what isn't.

What text here is inside a <details> and what isn’t?

The solution is… CSS. Style the <details> somewhat uniquely, and that problem goes away. Even if you want the typography to be the same, or you don’t want any exclusive styling until the <details> is opened, it’s still possible. Using an alpha-transparent fill, you can even make sure that deeper-nested <details> remain clear.

Here’s that CSS:

details[open] { --bg: rgb(0 0 0 / 0.2); background: var(--bg); outline: 1rem solid var(--bg); margin: 0 0 2rem 0;
}

And the demo:

JBS Foods, the meat supplier hit by a ransomware attack, admits it paid $11 million in ransom
Video Prospecting: What is it and Why You Should Use it?

Related Articles

How well can an AI mimic human ethics?

how-well-can-an-ai-mimic-human-ethics
When experts first started raising the alarm a couple decades ago about AI misalignment — the risk of powerful, transformative artificial intelligence systems that might not behave as humans hope…

How to Fetch Data in Svelte

Exploring the Potential of the Metaverse: A New World Awaits
This tutorial explores how you can consume and render data from an API in your Svelte application. You can interact with APIs in Svelte in the onMount() lifecycle hook using…

Your Team is Not “Them”

your-team-is-not-them
This post was written for engineering managers, but anyone is welcome to read it. Let’s talk for a moment about how we talk about our teams. This might not seem…

8 Best Web Crawlers To Get Better Data

8 Best Web Crawlers To Get Better Data
Crawlers are such essential tools on the Internet today that imagining a world without them would make navigating the web a different experience. Web crawlers assist in the operation of…

A Good Developer Is Hard To Find. Serverless Can Help.

a-good-developer-is-hard-to-find-serverless-can-help
Finding, training, and retaining top technical talent is consistently one of IT’s biggest challenges. A new generation of serverless application platforms is a powerful lure for both developers and administrators.…