简体   繁体   English

在div列引导程序中垂直对齐文本中心

[英]align text center vertically in div column bootstrap

simple question. 简单的问题。 Have tried different ways to figure out, but all failed. 尝试了其他方法来弄清楚,但都失败了。 All I need is to align text vertically center in each columns in one row. 我需要做的是在一行的每一列中垂直对齐文本。 Here is the code: 这是代码:

<div class='row '>
                <div class='col-md-3 col-xs-6'><p class="text-center ">dfgfg</p></div>
                <div class='col-md-3 col-xs-6'><p class="text-center">dfgfg</p></div>
                <div class='col-md-3 col-xs-6'><p class="text-center">dfgfg</p></div>
                <div class='col-md-3 col-xs-6'><p class="text-center">dfgfg</p></div>
            </div> 

The text shows at the top of each column, I dont want to use margin-top for each text. 文本显示在每一列的顶部,我不想为每个文本使用margin-top。 Any other way that I can align text vertically ? 还有其他方法可以使文本垂直对齐吗?

Thanks! 谢谢!

You can create it using line-height as follows,and put this class in to every <div> s 您可以使用line-height如下创建它,并将该类放入每个<div>

.yo{
  height: 80px;
  line-height: 80px;
}

Codepen example: http://codepen.io/anon/pen/rejBbY Codepen示例: http ://codepen.io/anon/pen/rejBbY

 .holider-height{ display:table; height:500px; } .holider-height p{ display:table-cell; vertical-align:middle } 
 <div class='row '> <div class='col-md-3 col-xs-6 holider-height'><p class="text-center ">dfgfg</p></div> <div class='col-md-3 col-xs-6 holider-height'><p class="text-center">dfgfg</p></div> <div class='col-md-3 col-xs-6 holider-height'><p class="text-center">dfgfg</p></div> <div class='col-md-3 col-xs-6 holider-height'><p class="text-center">dfgfg</p></div> </div> 

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

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