Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

details element seems to ignore display flex or grid?

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>
like image 754
George Mauer Avatar asked Oct 03 '19 19:10

George Mauer


People also ask

How do I get flexbox to ignore an element?

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.

What does display property flex do?

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.

Does display flex affect all children?

The flexbox code is triggered on the parent element, but affects all of the child elements.


1 Answers

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>
like image 152
G-Cyrillus Avatar answered Sep 19 '22 17:09

G-Cyrillus