对齐不同列上的图像底部(Bootstrap)

时间:2016-08-25 13:08:23

标签: html css twitter-bootstrap

在我的网站上,我有3个引导列,每个列都有一张照片。问题是标题有不同的长度,因此当我调整浏览器的大小(宽度为1100px)时,其中一张图片和上面的段落稍微偏移一点,然后是另一张图片。是否可以对齐照片和底部的pragraphs和顶部的标题?

以下是我遇到问题的JsFiddle

我现在不知道为什么但是在JsFiddle中列中的所有列都在一列中而不是多列(如在移动设备上),但是如果您保存它然后在浏览器中打开它,您可以看到问题

HTML:

<div class="container-fluid">
<div class="row ">
<div class="col-md-4 column">
  <center>
    <h1>Babababababababababababababa</h1>
    <p>2013 - Now</p>
    <div>
      <div class="container-images"> <img class="image" src="https://iso.500px.com/wp-content/uploads/2016/05/stock-photo-93725859-1500x1000.jpg">
        <div class="over">
          <p class="title">aaa</p>
          <p class="rayal">aaaaaa</p>
        </div>
      </div>
    </div>
  </center>
</div>
<div class="col-md-4 column">
  <center>
  <h1>Bababababababababababababababababa</h1>
  <p>2009 - 2013</p>
  <div class="container-images"> <img class="image" src="https://iso.500px.com/wp-content/uploads/2016/05/stock-photo-93725859-1500x1000.jpg">
    <div class="over">
      <p class="title">aaa</p>
      <p class="rayal">aaaaa</p>
    </div>
    </center>
  </div>
  <div class="col-md-4 column">
    <center>
    <h1>Babababababababababababababab</h1>
    <p>2007 - 2009</p>
    <div class="container-images"> <img class="image" src="https://iso.500px.com/wp-content/uploads/2016/05/stock-photo-93725859-1500x1000.jpg">
      <div class="over">
        <p class="title">aaa</p>
        <p class="rayal">aaaaa</p>
      </div>
      </center>
    </div>
  </div>
</div>

CSS:

.container-images {
  height: 300px;
  width: 75%;
  overflow: hidden;
  display: flex;
  /*  align-items: center;*/
  justify-content: center;
  position: relative;
  border-radius: 100px;
}

.image {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  background-size: cover;
  border-radius: 100px;
  display: block;
  float: left;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  margin-bottom: 50px;
}

.over {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 2;
  background: rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease-in-out;
  border-radius: 100px;
}

.title {
  margin-top: 100px;
  color: white;
  transition: all 0.5s ease-in-out;
  font-family: RobotoSlab-Regular;
  opacity: 0;
}

.rayal {
  opacity: 0;
  color: white;
  transition: all 0.5s ease-in-out;
  font-family: RobotoSlab-Regular;
}

.over:hover {
  background: rgba(0, 0, 0, 0.5);
}

.over:hover .title {
  margin-top: 0;
  opacity: 1;
}

.over:hover .rayal {
  opacity: 1;
}

1 个答案:

答案 0 :(得分:0)

这是flexbox的一个很好的例子。

以下是您的plunker的更新示例:

https://jsfiddle.net/eqcyyae9/9/

关于此的几点说明:

  1. 我删除了您的<center>代码。这些是折旧的,使用它们并不是一个好习惯(如here所述)。使用Bootstrap center-block CSS类可以实现相同的效果。
  2. 我删除了container-images课程的flexbox属性。在这种情况下你所做的中心由center-block处理,作为个人偏好,我只在必要时使用Flexbox,因此我的CSS会尽可能优雅地降低旧浏览器的性能。
  3. 我添加了一个container-content类,其中 上有flexbox。将space-between属性与flex-direction: column一起使用可使您的内容占用指定的空间(在此示例中为570px)。您的标题将始终贴在顶部,您的图像将粘在底部,任何额外的空间将最终介于两者之间(因此,空间介于两者之间)。如果您对此有更感兴趣,可以在此here上发表一篇非常好的文章。
  4. 作为旁注,plunker要求您将所有文件依赖项添加到&#34;外部资源&#34;部分而不是直接到HTML。这就是为什么你没有看到你的Bootstrap风格的原因。