This seems quite bizarre to me. You can see that we have a simple details element which should by all rights run horizontal. But it does not. grid
also seems to not work.
Why? I am not seeing anything in the spec about the layout model being any different for these elements.
details {
display: flex;
flex-direction: row;
}
<details open>
<summary>foo</summary>
<div>bar</div>
<div>baz</div>
</details>
You can use flex-shrink: 0 on the child elements to keep them from shrinking to fill the container. And use flex-wrap: wrap on the container/wrapper so your children will wrap down. Show activity on this post. Use flex: 0 0 100%; to the child you want to be in a new line and add flex-wrap: wrap on the wrapper.
The flex property sets the flexible length on flexible items. Note: If the element is not a flexible item, the flex property has no effect.
The flexbox code is triggered on the parent element, but affects all of the child elements.
You cannot overide the display behavior of a details element, but if the idea is to get children on a single line , then you can use display
or float
on the children :
a few example to test through different browsers before use.
borders, colors and background added for visual testing purpose
details {clear:both;margin:2em;border:solid;color:red;}
details.flkid {overflow:auto;/* to deaal with floatting children*/}
summary {background:yellow;}
details > *{padding:0 1em;color:green}
details.flkid > *{float:left;}
details.ib > *{display:inline-block;}
details.tbcl > *{display:table-cell;}
/* and so on with inline-table,inline-flex,inline-grid */
<details class="flkid" open>
<summary>foo</summary>
<div>bar</div>
<div>baz</div>
</details>
<details class="ib" open>
<summary>foo</summary>
<div>bar</div>
<div>baz</div>
</details>
<details class="tbcl" open>
<summary>foo</summary>
<div>bar</div>
<div>baz</div>
</details>
Disclaimer : the following snippets stands here only for the fun and should NOT be seen as a solution even if it seems to work in a few browsers :
div {
display: grid;
grid-template-columns: repeat(5, auto);
}
details {
display: contents/* removed from the flow, so the grid div becomes the parent */
}
div {
border: solid;
margin: 2px
}
details[open]> :not(summary) {
/* hide them from the flow except for summary */
position: absolute;
right: 100%;
}
div[class] {
grid-row: span 2;
}
<div>
<details><!-- attribute open removed you can add it if you want it closed at first :( -->
<summary>foo</summary>
<div>bar</div>
<div>baz</div>
<div>bar</div>
<div>baz</div>
<div>bar</div>
<div class>bazbazbazbazbazb</div>
<div>bar</div>
<div>baz</div>
<div>bar</div>
<div>baz</div>
<div>bar</div>
<div>baz</div>
</details>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With