I am trying to create three blocks with set height and width, aligned on top/bottom and also place couple elements inside them. My problem is that anytime I place additional DIVs into one of the elements are number of DIVs inside of each three elements is not the same, it will display the element with "missing" element 1 line lower. See code example below:
<div class="container">
<div class="d-inline-block border border-primary" style="width:16%;height:15vh;">
<div>thing1</div>
<div>XXX</div>
</div>
<div class="d-inline-block border border-success" style="width:16%;height:15vh;">
<div>thing2</div>
</div>
<div class="d-inline-block border border-primary" style="width:16%;height:15vh;">
<div>thing3</div>
<div>XXX</div>
</div>
</div>
I am using Bootstrap 5.0. Above code when rendered will show "thing2" box not aligned with other boxes, pushed lower.
Any ideas for this behaviour?
I’ve tried to wrap elements in additional div to set max height etc, I’ve played with position-relative/absolute, but I simply don’t understand that effect of one box on another.
2
Answers
The issue is occurring due to ‘d-inline-block’. The solution is to use the grid system, the below code helps:
If you are keeping using
display: inline-block
, addvertical-align: top
Here’s the example snippte: