I am trying to vertically align the content in posts using flexbox.
I want heading to be top aligned, footers to be bottom aligned, and text copy to be aligned with other posts' text copy. The length of heading and text copy would vary for different posts.
When I use justify-content: spance-between
in header, the text copy is being pushed to bottom. I want the text copy starting after the heading.
Could you please help me to solve this problem?
body {
background-color: #eee;
font-family: sans-serif;
}
.posts {
display: flex;
max-width: 700px;
margin: 0 auto;
}
.post {
flex-basis: calc(100%/3);
padding: 1em;
background-color: #fff;
display: flex;
flex-direction: column;
justify-content: space-between;
}
header {
display: flex;
flex-direction: column;
flex-grow: 1;
justify-content: space-between;
}
<div class="posts">
<section class="post">
<header>
<h4 class="post__heading">Lorem ipsum dolor sit amet</h4>
<p class="post__abstract">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</header>
<footer class="post__footer">
<p>Lorem ipsum dolor</p>
</footer>
</section>
<section class="post">
<header class="post__header">
<h4 class="post__heading">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt </h4>
<p class="post__abstract">Lorem ipsum dolor sit amet, </p>
</header>
<footer class="post__footer">
<p>Lorem ipsum dolor</p>
</footer>
</section>
<section class="post">
<header>
<h4 class="post__heading">Lorem ipsum dolor sit amet</h4>
<p class="post__abstract">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
</header>
<footer class="post__footer">
<p>Lorem ipsum dolor</p>
</footer>
</section>
</div>