So, here's the HTML structure that I'm working with:
<div class="category">
<div class="container bottom">
<h2>Name1</h2>
</div>
<div class="container top">
<h2>Name2</h2>
</div>
<div class="container ">
<h2>Name3</h2>
</div>
<div class="container">
<h2>Name4</h2>
</div>
<div class="container">
<h2>Name5</h2>
</div>
<div class="container">
<h2>Name6</h2>
</div>
<div class="container">
<h2>Name7</h2>
</div>
</div>
This is the CSS being used:
* {
margin: 0;
padding: 0;
}
.category {
text-align: center;
width: 95%;
margin: 0 auto;
}
.container {
display: inline-block;
width: 33%;
height: 4em;
}
h2 {
display: inline-block;
width: 100%;
}
.left > * {
text-align: left;
}
.right > *{
text-align: right;
}
.top > * {
vertical-align: top;
}
.bottom > * {
vertical-align: bottom;
}
The objective is to achieve a layout similar to this: Example
In the scenario presented in the image, all the .container
(gray boxes) are of equal size as defined in the CSS.
The issue I'm facing is that the vertical-align
property doesn't seem to be functioning correctly. I've explored solutions like the one provided in this CodePen example, which works without using display: table-cell
or other table-related techniques found on Stack Overflow. Why isn't it working with my specific HTML and CSS setup? Currently, all the <h2>
elements align in the middle instead of following the defined alignment :\