简体   繁体   English

Bootstrap垂直对齐小列不起作用

[英]Bootstrap Vertical Align Small Column Not Working

I have a bootstrap page that is basically two columns. 我有一个引导页面,基本上是两列。 One column has several columns and content in it which makes it very large and the other has just an image. 一栏包含数列和内容,这使其非常大,另一列仅具有图像。 I am trying to get that image vertically centered to the left column. 我试图使该图像垂直居中于左列。 My code looks like this: 我的代码如下所示:

<div class="row">
  <div class="col-sm-6 features">
    <div class="col-sm-12">
      This column has a lot of content and gets to be about 700px
    </div>
  </div>
  <div class="col-sm-6 small-column-align">
    <img src="inc/img/robot-warrior.jpg" width="717" height="837" alt="" style="max-width:80%; height:auto;"/>
  </div>
</div>

And my CSS for small-column-align is 我的小列对齐CSS是

.small-column-align{
    display: inline-block;
    vertical-align: middle;
    float: none;
}

For some reason the right column is always top aligned though. 出于某种原因,右列始终始终在顶部对齐。

The problem is that you are setting the column width to col-sm-6 on both div's, and that makes the two divs float one below each other, try to put it col-sm-5 on both and also put the class "small-column-align" to both div's. 问题是您在两个div上都将列宽设置为col-sm-6,这使两个div彼此上下浮动,请尝试将col-sm-5放在两个div上,然后将类“ small -column-align”到两个div。

HTML: HTML:

<div class="row">
<div class="col-sm-5 small-column-align">
    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
    <img src="http://labs.sogeti.com/wp-content/uploads/2015/03/google-car.jpg" width="717" height="837" alt="" style="max-width:80%; height:auto;"/>


    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
</div>
<div class="col-sm-5 small-column-align">


    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
    <img src="http://labs.sogeti.com/wp-content/uploads/2015/03/google-car.jpg" width="717" height="837" alt="" style="max-width:80%; height:auto;"/>
    <p>This is a text content for sm 5</p>
    <p>This is a text content for sm 5</p>
</div>

CSS: CSS:

.small-column-align {
    display: inline-block;
    vertical-align: middle;
    float: none;
}

Working fiddle: https://jsfiddle.net/DTcHh/12674/ 工作提琴: https : //jsfiddle.net/DTcHh/12674/

Hope it works, let me know your thoughts, 希望它能起作用,让我知道您的想法,

Leo. 狮子座

Can you try this? 你可以试试这个吗?

 .features-wrap { display: flex; align-items: center; } .features-wrap > div { float: none; display: inline-block; } .features { flex: 1; } .small-column-align { width: 10%; position: relative; } 
 <div class="row features-wrap"> <div class="col-sm-6 features"> <div class="col-sm-12"> This column has a lot of content and gets to be about 700px </div> </div> <div class="col-sm-6 small-column-align"> <img src="inc/img/robot-warrior.jpg" width="717" height="837" alt="" style="max-width:80%; height:auto;"/> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM