简体   繁体   English

Bootstrap 3在div中垂直对齐不起作用

[英]Bootstrap 3 vertical align in div doesn't work

I tried the following to vertically align text in a div ( fiddle ): 我尝试了以下方法在div( 小提琴 )中垂直对齐文本:

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-2">
            This should not be vertically centered
        </div>
        <div class="col-xs-2" style="display: table-cell; vertical-align: middle;">
            This should be vertically centered
        </div>
    </div>
</div>

However, the text remains top-aligned! 但是,文本仍保持顶部对齐! What am I doing wrong? 我究竟做错了什么?

(Note: this is not a duplicate, because the duplicate questions for this issue all recommend the above as the solution: I'm asking why the solution isn't working for me). (注意:这不是重复的,因为此问题的重复问题都建议使用以上作为解决方案:我在问为什么该解决方案不适用于我)。

It is top aligned, but unless you change the height it will look the same as middle or bottom aligned. 它是顶部对齐的,但是除非更改高度,否则它将看起来与中间或底部对齐的相同。

What you have now, but with background colors added to the divs: 您现在所拥有的,但是在div中添加了背景色:

 <div class="container-fluid"> <div class="row"> <div class="col-xs-2" style="background: #bbb;"> This should not be vertically centered </div> <div class="col-xs-2" style="background: #888; display: table-cell; vertical-align: middle;"> This should be vertically centered </div> </div> </div> 

What you will see if you give each a height of 50 pixels: 如果将每个像素的高度设置为50像素,将会看到以下内容:

 <div class="container-fluid"> <div class="row"> <div class="col-xs-2" style="background: #bbb; height: 50px;"> This should not be vertically centered </div> <div class="col-xs-2" style="background: #888; height: 50px; display: table-cell; vertical-align: middle;"> This should be vertically centered </div> </div> </div> 

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

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