-
Notifications
You must be signed in to change notification settings - Fork 669
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
Ability to style <details>/<summary> to be open (e.g. for print styles) #2084
Comments
/cc @tabatkins @fantasai |
Would be great it was specified to be open for print media by default (which I guess is what you mean?) |
Either that, or have some way to control it (like you'd want to control any other aspects when making decisions on how something should appear when printed). Currently, it's "style-resistant"... |
Aye, probably both. |
Nice idea. |
I'm thinking about whether it is possible to describe the behavior of The most straightforward approach might be defining a new pseudo-element (something like Maybe we can have that pseudo-element, but only allow |
I'm down with that approach. The UA stylesheet is then extremely trivial:
And overriding it is super easy. 👍 from me. |
+1 to any strategy that makes it possible to describe the behavior of Another way to approach this would be to have a generic selector for anonymous text nodes. So the default style rule for details:not([open]) > *:not(summary),
details:not([open]) > *text* {
/* any direct child elements other than summary, or any direct child text nodes */
display: none;
} There are other cases where it could be useful for authors to override default HTML renderings for anonymous text nodes, like A |
@AmeliaBR I had been planning to propose pseudo-elements for anonymous text boxes, first to the WICG then eventually here. For instance, a pseudo-element for anonymous block boxes would be generally useful in other cases as an approximate analogue to HTML’s paragraphs, e.g., anonymous-block “paragraphs” such as those in Having said all that, it is precisely the broadness in scope of such an anonymous-box selector that may make a |
Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2
Big fan of @tabatkins idea...
But @Loirooriol, any idea how you could make this work with your As an aside, could we also get a
But make the MDN Ref - ::-webkit-details-marker |
The regular
In that case, it makes more sense to define a pseudoelement for the auto-generated summary toggle, and allow it to have stacked psuedoelements on it: details::details-summary::marker,
details summary::marker {
/* styles for the disclosure marker */
} |
@AmeliaBR as well as something like this? details::details-summary {
content: 'Details';
display: list-item;
} |
@jonjohnjohnson Exactly! As I said earlier in the thread, I would very much like to get to the point where all of details/summary layout & rendering can be defined with a CSS model & customized by media queries. I hadn't been thinking about auto-generated summary toggles, but they definitely should be part of that. |
@jonjohnjohnson I don't think this would be a good fit for my
But this reparenting happens in the box tree. I think Then I think new pseudo-elements for detail parts would be better. |
Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2
Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <[email protected]> Reviewed-by: Christian Biesinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#589388}
Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <[email protected]> Reviewed-by: Christian Biesinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#589388}
Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <[email protected]> Reviewed-by: Christian Biesinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#589388}
…of <details> is ignored, a=testonly Automatic update from web-platform-testsAdd test asserting the display property of <details> is ignored Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <[email protected]> Reviewed-by: Christian Biesinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#589388} -- wpt-commits: 9d5d9aa80785d9726ed0a5eaab1a8d144fd4b560 wpt-pr: 12218
…of <details> is ignored, a=testonly Automatic update from web-platform-testsAdd test asserting the display property of <details> is ignored Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <[email protected]> Reviewed-by: Christian Biesinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#589388} -- wpt-commits: 9d5d9aa80785d9726ed0a5eaab1a8d144fd4b560 wpt-pr: 12218
I hope it's OK to chip in with an example of where this has stopped us from using details: At GDS we were considering creating our new accordion component using details elements as it would allow for better functionality when JavaScript is not available, we're deciding not to use the element for now but I think if this were possible to style when printed we'd likely use it. |
See also #3126, where Anne relays some requests for the ability to put ::before/::after in the contents of a |
I am making heavy use of these twisties for hiding diagrams or code snippets on markdown documentation pages (that get rendered to HTML). I have some styles that are activated when printing the document and for that purpose, I would also welcome a way to set |
…of <details> is ignored, a=testonly Automatic update from web-platform-testsAdd test asserting the display property of <details> is ignored Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <dgroganchromium.org> Reviewed-by: Christian Biesinger <cbiesingerchromium.org> Cr-Commit-Position: refs/heads/master{#589388} -- wpt-commits: 9d5d9aa80785d9726ed0a5eaab1a8d144fd4b560 wpt-pr: 12218 UltraBlame original commit: 3e84907d855160d165c2989d9cdd7f53f9ab16d7
…of <details> is ignored, a=testonly Automatic update from web-platform-testsAdd test asserting the display property of <details> is ignored Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <dgroganchromium.org> Reviewed-by: Christian Biesinger <cbiesingerchromium.org> Cr-Commit-Position: refs/heads/master{#589388} -- wpt-commits: 9d5d9aa80785d9726ed0a5eaab1a8d144fd4b560 wpt-pr: 12218 UltraBlame original commit: 3e84907d855160d165c2989d9cdd7f53f9ab16d7
…of <details> is ignored, a=testonly Automatic update from web-platform-testsAdd test asserting the display property of <details> is ignored Chrome, Safari, and Firefox pass. Edge hasn't implemented yet. The test still holds for the proposed new spec text in whatwg/html#3686 This scenario is discussed at the end of whatwg/html#603 but the conclusion drawn appears (to me) to be opposite what Chrome, Safari, and Firefox do. Related other issues: w3c/csswg-drafts#2084 whatwg/html#1839 Bug: 635282 Change-Id: Ice95225b3c9d5d90b80c657643d036490fd2e1b2 Reviewed-on: https://chromium-review.googlesource.com/1153651 Commit-Queue: David Grogan <dgroganchromium.org> Reviewed-by: Christian Biesinger <cbiesingerchromium.org> Cr-Commit-Position: refs/heads/master{#589388} -- wpt-commits: 9d5d9aa80785d9726ed0a5eaab1a8d144fd4b560 wpt-pr: 12218 UltraBlame original commit: 3e84907d855160d165c2989d9cdd7f53f9ab16d7
Hi, please add the ability to display by CSS, because I can't use the element in a responsive situation where it should always be open. Thanks. |
I was hoping |
+1. Another use case is to allow the open/closed state of the details element to be controlled by a preceding checkbox, using the sibling selector – something like
Or a more general toggle to expand or collapse all details elements on the page:
|
With the recent additions of ::details-content {
/* styles the shadow slot for details content */
}
::details-summary {
/* styles the shadow slot for details summary */
}
:open::details-summary {
/* styles the shadow slot for details summary when it is open */
}
:closed::details-summary {
/* style the shadow slot for details summary when it is closed */
}
:open::details-content {
/* styles the shadow slot for details content when it is open */
}
:closed::details-content {
/* styles the shadow slot for details content when it is closed */
} The |
Adding my voice to this. There's another issue with this - if a Here's a quick example:
I naïvely expected my browser to open the details and scroll me down to Again, this would be particularly useful for answer accordions etc. |
I’ve detailed the use case from @edent’s comment a bit more in whatwg/html#8509. |
@tabatkins any progress on this? |
|
Thank you for the pointer! After reading the other issue (and two other linked ones) I’m still not sure how I would use details ::details-content:has(:target) {
display: block /* or inline, or use visibility? */;
} |
@Boldewyn I wrote a demo for |
Just wanna add that, at least currently, this does not seem to be the style used by chrome (and Firefox, as of version 130). Simple example: <style>
.grid {
display: grid;
grid-auto-flow: row dense;
grid-template-columns: 1fr 1fr;
}
details {
display: contents;
}
</style>
<div class="grid">
<details>
<summary>summary 1</summary>
<div>contents 1</div>
</details>
<details>
<summary>summary 2</summary>
<div>contents 2</div>
</details> Here, we see that regardless of whether the details are open or not, the contents are included as a separate grid cell. If you add in additional Personally, I would like this to be the default styles per the spec, but I think it's worth saying that it's not, at least implicitly per the behaviour we get when the details are closed. |
(Not quite sure which spec this would relate to specifically, sorry)
If a page uses
<details>
/<summary>
expand/collapse blocks, there currently appears to be no way to open these via CSS. This poses problems for print styling: if I wanted to have these blocks appear open when printed, it seems that the only solution is to first run JS over the document and add theopen
attribute on the<details>
.The text was updated successfully, but these errors were encountered: