I am re-writing my question after digging further and finding that this issue is only evident on some devices, suggesting its related to viewport size.
As you can see in the code, the parent has a set height + width and the children should all have identical heights.
Yet as you can see in the picture below, a screenshot from my laptop, the code in the demo sometimes produces children of different sizes based on the size of the parent container and as I just mentioned, the device its viewed on.
So how can I ensure they appear equal heights regardless of the device they are viewed on/size of the parent container.
console.clear();
.header {
height: 200px;
width: 500px;
margin: auto;
display: flex;
}
.flex-container {
height: 20px;
width: 20px;
background-color: black;
margin: auto;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
transform: scale(5);
}
.child {
display: block;
background-color: white;
height: 10%;
width: 90%;
}
<div class="header">
<div class="flex-container">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</div>
<script src="https://cdn.tailwindcss.com"></script>
2
Answers
Try using "flex-basis" along with the "max-width". this will ensure a more robust construction
As you already choose to build the
flex-box
flow you may ignore the width of children elements – just leave them with full scale. Set only the height param. Also, for parent container you may add some paddings and gaps – it’ll plays perfectly with flex-box.Down there a sample with
TailwindCSS
(as I saw you already added it to your example), but you free to transform it all into custom styles for your best practice.