<script>
document.documentElement.dataset.embed = window.location.search.includes('type=embed') ? "yep" : "nope";
</script>
<main>
<h1>Styling <code><details></code>: the <code>::details-content</code> pseudo</h1>
<p class="warning">Your browser does not support <code>::details-content</code>, so this demo won’t work as intended. Please use a browser with support – such as Chrome 131 or newer – to check out this page.</p>
<h2>Demo</h2>
<div id="demo">
<div id="example1">
<details>
<summary>First details element</summary>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<p>Architecto cupiditate ea optio modi quas sequi, esse libero asperiores debitis eveniet commodi hic ad.</p>
<p>Illum fugit mollitia autem corrupti, explicabo aliquam?</p>
</details>
</div>
<div id="example2">
<details>
<summary>Second details element</summary>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<p>Architecto cupiditate ea optio modi quas sequi, esse libero asperiores debitis eveniet commodi hic ad.</p>
<p>Illum fugit mollitia autem corrupti, explicabo aliquam?</p>
</details>
</div>
</div>
<p>Demo for <a href="https://developer.chrome.com/blog/styling-details" target="_top">https://developer.chrome.com/blog/styling-details</a>.</p>
<h2>The Code</h2>
<h3>First details element</h3>
<pre><code>details::details-content {
border: 5px dashed hotpink;
}</code></pre>
<h3>Second details element</h3>
<pre><code>details[open]::details-content {
border: 5px dashed hotpink;
}</code></pre>
</main>
@supports selector(::details-content) {
.warning {
display: none;
}
}
#example1 details::details-content {
border: 5px dashed hotpink;
}
#example2 details[open]::details-content {
border: 5px dashed hotpink;
}
@layer reset {
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
}
html {
font-size: 14px;
}
}
@layer baselayout {
html {
color: #444;
font-family: system-ui;
line-height: 1.42;
overscroll-behavior-x: none;
overflow: auto;
}
main {
max-width: 90ch;
margin: 0 auto;
padding-bottom: 10rem;
}
p {
margin-bottom: 1em;
}
h1, h2 {
margin: 4em 0 1em;
}
h3 {
margin: 1em 0 0.5em;
}
#demo {
padding: 1em;
border: 1px solid #ccc;
background: #f4f6f9;
}
}
@layer code {
pre {
border: 1px solid #dedede;
padding: 1em;
background: #f7f7f7;
font-family: "Courier 10 Pitch", Courier, monospace;
overflow-x: auto;
border-left: 0.4em solid cornflowerblue;
tab-size: 4;
}
code:not(pre code) {
background: #f7f7f7;
border: 1px solid rgb(0 0 0 / 0.2);
padding: 0.1rem 0.3rem;
margin: 0.1rem 0;
border-radius: 0.2rem;
/* display: inline-block; */
box-decoration-break: clone;
white-space: pre-wrap;
}
}
@layer warning {
.warning {
box-sizing: border-box;
padding: 1em;
margin: 1em 0;
border: 1px solid #ccc;
background: rgba(255 255 205 / 0.8);
}
.warning > :first-child {
margin-top: 0;
}
.warning > :last-child {
margin-bottom: 0;
}
.warning a {
color: blue;
}
.warning--info {
border: 1px solid #123456;
background: rgb(205 230 255 / 0.8);
}
.warning--alarm {
border: 1px solid red;
background: #ff000010;
}
}
/* Hide a bunch of stuff when embedded */
:root[data-embed="yep"] {
main {
padding: 2em 1em;
:not(p.warning, p.warning *, #demo, #demo *, #demo ~ p, #demo ~ p *) {
display: none;
}
}
#demo ~ p {
margin-top: 1em;
text-align: center;
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.