One issue with Flexbox is that the entire row's height changes to match the biggest element in it, thus not achieving a Masonry-type layout.
I am currently trying to use Semantic UI's card
views together with CSS columns instead of their cards
class to avoid this issue.
The problem with that is that Chrome seems to break apart the card element into various places in the columns while Firefox renders it just fine. It seems that the break-inside
CSS property is intended to fix this, but it doesn't seem to work in Chrome.
body {
padding: 10px;
width: 100%
}
.container {
padding: 15px;
-moz-column-count: 5;
-moz-column-gap: 10px;
-webkit-column-count: 5;
-webkit-column-gap: 10px;
column-count: 5;
column-gap: 10px;
width: 100%;
}
.container > .card {
width: 90% !important;
display: inline-block !important;
margin-top: 0px !important;
-webkit-column-break-inside: avoid !important;
page-break-inside: avoid !important;
break-inside: avoid-column !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.10/semantic.min.css" rel="stylesheet"/>
<div class="container">
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
<div class="ui card">
<div class="image">
<img src="http://via.placeholder.com/150x150">
</div>
<div class="content">
<a class="header">Kristy</a>
<div class="meta">
<span class="date">Joined in 2013</span>
</div>
<div class="description">
Kristy is an art director living in New York.
</div>
</div>
<div class="extra content">
<a>
<i class="user icon"></i> 22 Friends
</a>
</div>
</div>
</div>
A CodePen with the example code
As you can see in the below screenshots, the content of the cards flies back to the previous column while the image stays where it should.
Screenshot of Chrome full page render
align-items: stretch
) is true, but it's not the cause of the second part (preventing a Masonry layout). – Weidnerdisplay: flex;align-items: flex-start;
to the container to override the stretching andflex-shrink: 0;
to the cards, but that just put them all on the same row that overflows the container. I tried addingflex-flow: column wrap;
but now it's just one long column. – Bightmax-height
on the container forcolumn wrap
to work. – Weidnercolumn wrap
method, only if the container is the height of the viewport. – Weidner