Trying to create a paragraph that expands dynamically by clicking on summary tags, using only HTML/CSS:
div.textexpand {
display: inline-block;
background-color: grey;
}
div.textexpand > * {
display: inline;
}
details, details[open] {
background-color: yellow;
}
details > span {
display: inline;
}
details > summary {
list-style: none;
display: inline;
cursor: pointer;
text-decoration: underline;
}
<div class="textexpand">
<span>Lorem ipsum</span>
<details>
<summary>dolor</summary>
<span>sit amet, consetetur sadipscing elitr,</span>
</details>
<span>sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam</span>
<details>
<summary>voluptua.</summary>
<span>
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est
Lorem ipsum dolor sit amet.
</span>
</details>
</div>
Result: the first <details> element expands as expected.
But as soon as the additional information of the <details> element overflows the surrounding <div>, the whole details element (summary and additional information) breaks to the next line (tested with Firefox 92).
Expected: details contents (yellow) should always break at the border of the surrounding div box (grey).
Is there a simple way to do this with CSS that I'm missing?
I wasn't able to pull it off using various values for white-space (no effect short of preventing line breaks altogether) and break-after (no effect), and I'm trying to avoid Javascript solutions like this.