Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

css - Replace the expand ( ?) icon of HTML5 details tag

I use the <details> tag in my website and I want to change the design of the expand/collapse arrows. Is it possible to set a picture instead of the existing characters? Is it possible to change the position of the arrows? I want it to be on the right side and not next to the summary text.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...