0

When placing an <details> element inside a <div> with display: flex the width of the <details> element will equal the <summary> element when collapsed and will grow when uncollapsed to fit its content.

Example:

.flex {
  display: flex;
}

details {
  background-color: red;
}
<div class="flex">
  <details>
    <summary> short </summary>
    <p> very long and detailed description </p>
  </details>
</div>

What I want is that the width of the <details> element is consistent regardless if it is collapsed or not. Ideally such that it fits its content.

In short how do I prevent it from shrinking when collapsed.

Sam Coutteau
  • 357
  • 2
  • 15

4 Answers4

0

You can achieve this by setting a fixed width on the details element.

details {
  background-color: red;
  width: 50px;
}
Casper Kuethe
  • 1,070
  • 8
  • 13
0

You can try code below: Hope helpful for you

.flex {
  display: flex;
}

details {
  background-color: green;
  flex: 1;
}
<div class="flex">
  <details>
    <summary> short </summary>
    <p> very long and detailed description </p>
  </details>
</div>
lost you
  • 111
  • 2
0

Specify a flex-basis on details.

.flex {
  display: flex;
}

details {
  background-color: red;
  flex-basis: 50%;
}
<div class="flex">
  <details>
    <summary> short </summary>
    <p> very long and detailed description </p>
  </details>
</div>
Kameron
  • 10,240
  • 4
  • 13
  • 26
0

solution, you need min 1 li

 <details>
    <summary> <li></li> short </summary>
    <p> very long and detailed description </p>
  </details>
        

so when you will put flex on summary , you will have a arrow

jon
  • 1,494
  • 3
  • 16
  • 29