I am currently facing an issue with a flex parent div that does not adjust its width to fit the child elements within. How can I resolve this?
Essentially, I need to create a dynamic two-dimensional matrix where the user sets the dimensions, resulting in varying amounts of elements and line breaks as shown in the following code snippet. The child elements have fixed width and height.
.parent {
display: flex;
flex-wrap: wrap;
background-color: silver;
padding: 5px;
border-radius: 10px;
}
.child {
width: 40px;
height: 40px;
border-radius: 10px;
background-color: gold;
margin: 5px;
}
.line-break {
width: 100%;
}
<div class='parent'>
<div class='child'></div>
<div class='child'></div>
<div class='child'></div>
<div class='child'></div>
<div class='line-break'></div>
<div class='child'></div>
<div class='child'></div>
<div class='child'></div>
</div>
Here is a link to the fiddle showcasing the code: https://jsfiddle.net/NoisyApple/4g8n3vfL/3/
I anticipate the parent div automatically adjusting its width based on the elements it contains.