html - Bootstrap 垂直对齐小列不起作用

标签 html css twitter-bootstrap-3

我有一个引导页面,基本上是两列。一栏中有多个栏和内容,这使得它非常大,而另一栏只有一张图片。我试图让该图像垂直居中于左列。我的代码如下所示:

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

我的 small-column-align CSS 是

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

由于某些原因,右列总是顶部对齐。

最佳答案

问题是您在两个 div 上都将列宽设置为 col-sm-6,这使得两个 div 彼此 float 一个,尝试将其设置为 col-sm-5 并同时将类“small-column-align”到两个 div。

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:

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

工作 fiddle :https://jsfiddle.net/DTcHh/12674/

希望它有用,让我知道你的想法,

狮子座。

关于html - Bootstrap 垂直对齐小列不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32877759/

相关文章:

javascript - 显示选定的图像、网页

css - IE7/IE8 - 不显示背景图片

css - 在面板标题上添加按钮插件/输入组

html - 在导航中显示 'active' 选项卡

java - 如何修复 HTML 代码中的 Open Quote 错误消息?

javascript - Meteor contentEditable 字段不起作用

html - 为什么单词不垂直居中

html - 图片和 alt 中的 CSS 选择器

css - Internet Explorer 7 中的自举网格

html - 具有最大宽度/高度且没有 CSS 的 HTML 中的响应图像