-
Notifications
You must be signed in to change notification settings - Fork 23k
Add ::details-content page
#37118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add ::details-content page
#37118
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
83fe58b
Add `::details-content` page
lukewarlow 02cc081
Address comments
lukewarlow 0c50bde
Add example descriptions
chrisdavidmills 2055f21
Merge branch 'main' into details-content
chrisdavidmills 06d7362
Merge branch 'main' into details-content
bsmth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| --- | ||
| title: "::details-content" | ||
| slug: Web/CSS/::details-content | ||
| page-type: css-pseudo-element | ||
| browser-compat: css.selectors.details-content | ||
| --- | ||
|
|
||
| {{CSSRef}} | ||
|
|
||
| The **`::details-content`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the expandable/collapsible contents of a {{HTMLElement("details")}} element. | ||
|
|
||
| [//]: # '{{EmbedInteractiveExample("pages/tabbed/pseudo-element-details-content.html", "tabbed-shorter")}}' | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```css | ||
| selector::details-content | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Basic example | ||
|
|
||
| In this example the `::details-content` pseudo-element is used to set a {{cssxref("background-color")}} on the content of the {{HTMLElement("details")}} element. | ||
|
|
||
| #### HTML | ||
|
|
||
| ```html | ||
| <details> | ||
| <summary>Click me</summary> | ||
| <p>Here is some content</p> | ||
| </details> | ||
| ``` | ||
|
|
||
| #### CSS | ||
|
|
||
| ```css | ||
| details::details-content { | ||
| background-color: #a29bfe; | ||
| } | ||
| ``` | ||
|
|
||
| #### Result | ||
|
|
||
| {{EmbedLiveSample("Basic_example", "100%", 150)}} | ||
|
|
||
| ### Transition example | ||
|
|
||
| In this example the `::details-content` pseudo-element is used to set a {{cssxref("transition")}} on the content of the {{HTMLElement("details")}} element so that it smoothly fades into view when expanded, and fades out again when collapsed. To achieve this, two separate transitions are specified inside the `transition` shorthand property: | ||
|
|
||
| - The {{cssxref("opacity")}} property is given a basic transition over `600ms` to create the fade-in/fade-out effect. | ||
| - The {{cssxref("content-visibility")}} property (which is toggled between `hidden` and `visible` when the `<details>` content is expanded/collapsed) is also given a basic `600ms` transition, but with the {{cssxref("transition-behavior")}} value `allow-discrete` specified. This opts the browser into having a transition started on `content-visibility`, the animation behavior of which is [discrete](/en-US/docs/Web/CSS/CSS_animated_properties#discrete). The effect is that the content is visible for the entire duration of the transition, allowing other transitions to be seen. If this transition was not included, the content would immediately disappear when the `<details>` content was collapsed — you wouldn't see the smooth fade-out. | ||
|
|
||
| #### HTML | ||
|
|
||
| ```html | ||
| <details> | ||
| <summary>Click me</summary> | ||
| <p>Here is some content</p> | ||
| </details> | ||
| ``` | ||
|
|
||
| #### CSS | ||
|
|
||
| ```css | ||
| details::details-content { | ||
| opacity: 0; | ||
| transition: | ||
| opacity 600ms, | ||
| content-visibility 600ms allow-discrete; | ||
| } | ||
|
|
||
| details[open]::details-content { | ||
| opacity: 1; | ||
| } | ||
| ``` | ||
|
|
||
| #### Result | ||
|
|
||
| {{EmbedLiveSample("Transition_example", "100%", 150)}} | ||
|
|
||
| ## Specifications | ||
lukewarlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - [`<details>`](/en-US/docs/Web/HTML/Element/details) | ||
lukewarlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - [`<summary>`](/en-US/docs/Web/HTML/Element/summary) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.