2017-06-19 51 views
0

我想在底部对齐img在jumbotron中,但无法弄清楚。不能底部对齐图像在jumbotron

<div class="jumbotron"> 
    <div class="container"> 
     <div class="row"> 
      <div class="col-lg-8"> 
       <h1>Hello, world!</h1> 
       <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p> 
       <p><a class="btn btn-primary btn-lg">Learn more »</a></p> 
      </div> 
      <div class="col-lg-4 text-center"> 
       <img src="http://via.placeholder.com/200x200"> 
      </div> 
     </div> 
    </div> 
</div> 

我尝试添加以下的CSS

.vertical-bottom { 
    display: flex; 
    align-items: bottom; 
} 

然后将包含IMG

<div class="col-lg-4 text-center vertical-bottom"> 

这不起作用增加的附加类的DIV,为什么很难在引导中垂直对齐的东西?

+0

问题不在于引导程序。垂直居中的东西一直是半困难的,直到弹性盒被支持。但Bootstrap 4允许您使用与其列/网格系统配合使用的弹性框类。回到问题,你想达到什么结果?图像将水平居中,但低于标题,文本和按钮? –

+0

@ hunter-mitchell我希望图像水平居中,底部与包含标题,文本和按钮的div侧面对齐。所以1行与2列两个底部对齐。我考虑试图找出标题,文本和按钮的div的高度,然后设置图像的顶部边距以获得底部对齐。但是,我不确定如何获得该div的高度? – user13317

+0

Bootstrap 4具有一个非常好的支持flexbox的网格系统。我建议您使用它(不需要移除两列上的浮动块并手动定位每列,以便可以将儿童高度设置为100%)。当我得到一个改变生病的时候抛出一个例子。 –

回答

1

这里有种代码:

Bootply

的CSS媒体查询设置为1200,因为我看到你正在使用COL-LG-XX

@media screen and (min-width:1200px) { 
    .flex_container img{ 
     object-fit: contain; 
     object-position: 100% 100%; 
    } 
    .flex_container { 
    display: flex; 
    } 
} 

Html

<div class="jumbotron"> 
    <div class="container"> 
     <div class="row flex_container"> 
      <div class="col-lg-8"> 
       <h1>Hello, world!</h1> 
       <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p> 
       <p><a class="btn btn-primary btn-lg">Learn more »</a></p> 
      </div> 
      <div class="col-lg-4 text-center flex_container"> 
       <img src="http://via.placeholder.com/200x200" style=""> 
      </div> 
     </div> 
    </div> 
</div> 
+0

谢谢,这工作!但是我可能会开始迁移到Bootstrap 4,似乎可以按照@ hunter-mitchell的建议提供一些更好的Flexbox支持。 – user13317

+0

虽然,我似乎失去了对水平放置的控制。 text_center什么都不做...... – user13317

+0

@ user13317使用justify-content:center;而不是text-align:center; – pbenard