使用flex(多个元素)进行垂直和水平定心

时间:2017-01-13 12:14:07

标签: html css twitter-bootstrap-3 flexbox

在我目前的场景中,我使用Bootstrap和col - * - 4有6个等间距的3到3块。这些块只是略微造型的拇指指甲(仍然使用Bootstrap 3)。

在这些方框中,我在底部有文字,我找到了:

position: absolute; bottom:0;

除此之外,我还有一张图片,上面是我在DIV中定位的:

 height: 400px;
 display: flex;
 justify-content: center;
 align-items: center;

最终结果是

enter image description here

我的问题是,使用flex时,不是使用固定高度,而是在缩略图的整个区域内使图像居中,文本保留在底部。

我可以制作整个缩略图display:flex吗?

添加了以下代码

HTML

<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<div class="thumbnail grey mb-30">
    <div class="img-center">
        <img src="img/picto/originals/png/Heart/Newable_Pictogram_CoolGrey_HEART.png" class="img-responsive picto_padding" alt="...">
    </div>

    <div class="caption">
        <h3>Responsibe finance</h3>
        <p>We’re the responsible alternative for those who find High Street bank finance difficult to obtain. </p>
     </div>
</div>
</div>

CSS

.img-center {
height: 350px;
display: flex;
justify-content: center;
align-items: center;
}

 .grey {
    background: #f0f0f0;
}
.thumbnail {
    border: none;
}
.mb-30 {
    margin-bottom: 30px;
}
.thumbnail {
    border: none;
    min-height: 450px;
    position: relative;
}

.caption{
    position:absolute; 
    bottom:0;
}

2 个答案:

答案 0 :(得分:0)

也许使用这种结构..

canDisplayBannerAds

答案 1 :(得分:0)

是否特别需要img-center容器? 为什么不删除img-center并设置缩略图以显示flex?

https://jsfiddle.net/bashaen/wbrzfds7/

<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<div class="thumbnail grey mb-30">
<img src="img/picto/originals/png/Heart/Newable_Pictogram_CoolGrey_HEART.png" class="img-responsive picto_padding" alt="...">

    <div class="caption">
        <h3>Responsibe finance</h3>
        <p>We’re the responsible alternative for those who find High Street bank finance difficult to obtain. </p>
     </div>
</div>

.grey {
    background: #f0f0f0;
}
.thumbnail {
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
}
.mb-30 {
    margin-bottom: 30px;
}
.thumbnail {
    border: none;
    min-height: 450px;
    position: relative;
}

.caption{
    position:absolute; 
    bottom:0;
}