簡體   English   中英

Flexbox中統一的自動商品高度

[英]Uniform auto items height in flexbox

我有一個頁面,其中包含一個伸縮框和多個伸縮項,伸縮項代表帖子,這些帖子有時標題較大,有時標題較小,導致每行高度不一致,如您在此圖中看到的:

頁

我不想設置固定的高度,因為現在小標題將有很大的空白空間。 相反,我希望每行的高度是恆定的,並且等於包含post元素的最小高度。

這是我的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;
}

這是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>

站點參考: https : //squircleart.github.io/posts.html

這里的主要問題是post的父元素,即包裝它的鏈接。

如果您給它display: flex它將起作用

.post-containter > a {
  display: flex;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM