I'm currently working on developing a menu system that incorporates images and text above and below each image. The content is dynamic, so I need the menu layout to display with equal spacing between each image, creating a grid-like pattern both horizontally and vertically.
However, one issue I've encountered involves the varying lengths of text. When the text exceeds the length of the image, it causes the div container to expand unevenly, resulting in an awkward gap between images that were originally equally spaced.
To address this problem, I believe adjusting the size of the other divs to match the largest div would be the most effective solution. Yet, I am uncertain how to implement this.
I have experimented with flexbox and utilized the flex-wrap property, which caused the text to wrap nicely. Nonetheless, I haven't been successful in achieving consistent equal-spacing between all images.
Can someone guide me on how to accomplish this?
Below is the code snippet I am using:
#outer {
display: flex;
}
#main {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
border: solid black 25px;
border-radius: 25px;
width: 450px;
height: 500px;
padding: 20px;
}
.section {
background-color: #ddd;
padding: 15px;
}
.label, .icon {
text-align: center;
}
<div id="outer">
<div id="main">
<div class="section">
<div class="label">Label 1AAAAAAAAAAA</div>
<div class="icon"><img src="https://via.placeholder.com/75"></div>
<div class="label">Label 1B</div>
</div>
<div class="section">
<div class="label">Label 2A</div>
<div class="icon"><img src="https://via.placeholder.com/75"></div>
<div class="label">Label 2B</div>
</div>
<div class="section">
<div class="label">Label 3A</div>
<div class="icon"><img src="https://via.placeholder.com/75"></div>
<div class="label">Label 3B</div>
</div>
<div class="section">
<div class="label">Label 4A</div>
<div class="icon"><img src="https://via.placeholder.com/75"></div>
<div class="label">Label 4B</div>
</div>
<div class="section">
<div class="label">Label 5A</div>
<div class="icon"><img src="https://via.placeholder.com/75"></div>
<div class="label">Label 5B</div>
</div>
</div>
</div>
Additionally, I'm trying to resolve why the height of my section divs keeps increasing. Any advice on this matter would be greatly appreciated as well.