According to MDN’s section on the topic, customising the disclosure marker, the standards-compliant way to do this is via the list-style
CSS property, since <details>
tags have display: list-item
applied to them.
Unfortunately Chrome does not support this (yet), and requires customisation via the -webkit-details-marker
pseudo-element.
To make styling easy and consistent across browsers, you can hide both the list-item marker and the WebKit marker, and then add the actual icon in the ::before
pseudo-element:
details > summary {
list-style-type: none;
}
details > summary::-webkit-details-marker {
display: none;
}
details > summary::before {
content: '??';
}
details[open] > summary::before {
content: '??';
}
details {
border: 1px solid gray;
border-radius: 0.2rem;
padding: 0.5rem;
}
details[open] > summary {
margin-bottom: 0.5rem;
}
<details>
<summary>An example</summary>
With some example text shown when expanded.
</details>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…