I have a page with a flex box and multiple flex items, flex items represent posts, those posts sometimes have large titles and sometimes small ones resulting in a non uniform height per row, as you may see in this image:
I don't want to set a fixed height because now small titles will have a big empty space. Rather, I want the height to be constant per row and is equal to the least height possible to contain the post elements.
Here is my Css:
/* Post Pages */
.post-containter {
padding:4%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
align-content: space-around;
}
.post {
text-align: center;
width: 250px;
padding: 10px 10px;
border-radius: 5px;
border: thin solid #f8f8f8;
box-shadow: 1px 1px 2px rgba(0,0,0,0.1);
background-color: white;
display: inline-block;
margin-top: 15px;
transition: box-shadow 150ms ease-in-out;
}
.post h5 {
font-weight: normal;
margin:5px;
}
.post:hover {
box-shadow: 0px 0px 25px rgba(0,0,0,0.1);
}
.posts-head {
text-align: center;
font-weight: bolder;
font-size: 50px;
}
img.post-image {
max-width: 100%;
height: auto;
border-top: 3px solid #558abb;
border-bottom: 3px solid #00c8bd;
}
And here is the HTML:
<div class="post-containter">
{% for post in site.posts %}
<a href="{{post.url}}">
<div class="post">
<img class="post-image" src="{{ post.image_path }}" alt="{{ post.title }}"/>
<h5>{{ post.title }}</h5>
</div>
</a>
{% endfor %}
</div>
Site reference: https://squircleart.github.io/posts.html
答案 0 :(得分:1)
The main problem here is the parent element of the post
, the link that wraps it.
If you give it display: flex
it will work
.post-containter > a {
display: flex;
}