I'm currently developing an interactive "accordion" component that can accommodate multiple child elements. Each child item closes to the height of its header, but expands evenly with other open siblings when activated. If this explanation is unclear, feel free to click on the provided CodePen link for reference.
Utilizing flexbox seemed like a suitable approach for this project, and I managed to create a design using flex-grow that functions perfectly in Firefox and Chrome. However, Safari presents an issue where expanding one item prevents effortless expansion of another due to limited vertical space allocation.
<div class="wrapper">
<div class="item">
<h3>foo</h3>
<p>Lorem ipsum</p>
</div>
<div class="item">
<h3>foo</h3>
<p>Lorem ipsum</p>
</div>
<div class="item">
<h3>foo</h3>
<p>Lorem ipsum</p>
</div>
<div class="item">
<h3>foo</h3>
<p>Lorem ipsum</p>
</div>
</div>
.wrapper
display: flex
flex-direction: column
.item
// default closed height
flex-basis: 20px
flex-grow: 0
transition: flex-grow .3s ease-out
&.open
flex-grow: 1
https://codepen.io/suchesuch/pen/EEazdV
If anyone has suggestions on how to address this Safari compatibility issue or knows of an alternative CSS property to achieve the desired outcome, I would greatly appreciate your input.
Just to clarify, I am specifically seeking a CSS solution, preferably elegant yet functional, without resorting to JavaScript calculations to maintain code cleanliness. Thank you for taking the time to review my query!