Within my flex wrapper, I have multiple column components with various flex items inside. Each column displays content adjacent to each other.
The challenge is to ensure that the top item in each column has an equal height, creating a row-like effect. I'm looking for a solution that doesn't rely on fixed heights as it could cause display issues when users adjust font sizes or if the content length changes within a CMS. Can Flexbox be used to achieve this? If not, are there alternatives such as CSS Grid?
For example:
html:
<div class="wrapper">
<div class="column">
<div class="topRow">
Some content
</div>
<p>Needs to align</p>
<p>Something</p>
<p>Something</p>
<p>Something</p>
</div>
<div class="column">
<div class="topRow">
Some content which is a bit longer
</div>
<p>Needs to align</p>
<p>Something</p>
<p>Something</p>
<p>Something</p>
</div>
<div class="column">
<div class="topRow">
Some content
</div>
<p>Needs to align</p>
<p>Something</p>
<p>Something</p>
<p>Something</p>
</div>
</div>
css:
.wrapper {
display: flex;
max-width: 600px;
}
.column {
flex: 1 1 0;
border-right: 1px solid black;
text-align: center;
}
https://i.sstatic.net/Xt02k.png
UPDATE: A solution using Flexbox can be implemented like so:
html:
<div class="wrapper">
<div class="column">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vitae mauris arcu. Donec et lorem ac nulla scelerisque egestas.
</div>
<div class="info">
<div class="infoRows">
<p>Needs to align</p>
<p>Something</p>
<p>Something</p>
<p>Something</p>
</div>
</div>
</div>
<div class="column">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vitae mauris arcu. Donec et lorem ac nulla scelerisque egestas.
</div>
<div class="info">
<div class="infoRows">
<p>Needs to align</p>
<p>Something</p>
<p>Something</p>
<p>Something</p>
</div>
</div>
</div>
<div class="column">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vitae mauris arcu. Donec et lorem ac nulla scelerisque egestas.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vitae mauris arcu. Donec et lorem ac nulla scelerisque egestas.
</div>
<div class="info">
<div class="infoRows">
<p>Needs to align</p>
<p>Something</p>
<p>Something</p>
<p>Something</p>
</div>
</div>
</div>
<div class="column">
<div class="header">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras vitae mauris arcu. Donec et lorem ac nulla scelerisque egestas.
</div>
<div class="info">
<div class="infoRows">
<p>Needs to align</p>
<p>Something</p>
<p>Something</p>
<p>Something</p>
</div>
</div>
</div>
</div>
css:
.wrapper {
display: flex;
justify-content: center;
flex-direction: row;
@media (max-width: 900px) {
flex-direction: column;
}
}
.column {
padding: 10px;
display: flex;
flex-direction: column;
width: 100%;
}
.info {
display: flex;
flex: 1;
align-items: end;
}
.infoRows {
flex-direction: column;
width: 100%;
}
.infoRows p {
border-top: 1px solid black;
text-align: center;
}
Output: https://i.sstatic.net/hWZSd.png