I am working on a layout where I need three flex items (rows) in a flex container, and my requirement is to justify them as space-between
... The first row will consist of cloud tags, the second will have a price, and the third will contain a Read more link.
However, there may be cases where only the last row (Read more link) needs to be displayed for specific items.
In such scenarios, to maintain consistency, I want the Read more link to always be positioned at the bottom of the container; but using space-between
alone does not achieve this desired layout...
Is there a way to set a fallback justify-content
property to end
when there is only one child item present?
.container {
background-color: #aaa;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-end;
height: 200px;
margin-bottom: 20px;
}
.tags {
display: flex;
}
.tags span {
background-color: #f0f;
padding: 10px;
margin: 0 0 0 10px;
}
.price {
display: flex;
background-color: #ff0;
padding: 10px;
font-size: 150%
}
.read-more {
display: flex;
background-color: #0ff;
padding: 10px;
}
<div class="container">
<div class="tags">
<span>tag 1</span><span>tag2</span><span>tag 3</span>
</div>
<div class="price">
$100
</div>
<div class="read-more">
<a href="#">Read more >></a>
</div>
</div>
<div class="container">
<div class="read-more">
<a href="#">Read more >></a>
</div>
</div>