简体   繁体   English

如何使用引导程序垂直对齐不同大小的文本

[英]How to vertically align text of different sizes with bootstrap

Alright, so I've gone through and have tried several different solutions but I haven't found one that works the way I want it to so hence me reaching out for help. 好吧,所以我经历了很多尝试,并尝试了几种不同的解决方案,但是我还没有找到一种能以我想要的方式工作的解决方案,因此我寻求帮助。

Here is an example of my current code: 这是我当前代码的示例:

<div class="row">
  <div class="col-md-3">
    <h3>
      Operating Systems:
    </h3>
  </div>
  <div class="col-md-8">
    <ul>
      <li>Windows</li>
      <li>Linux</li>
    </ul>
  </div>
</div>

This gives me the following: screenshot 这给了我以下内容: 屏幕截图

By adding the following style to the columns: 通过向列添加以下样式:

<style>
.col-height {
  display: table-cell;
  float: none;
  height: 100%;
</style>

I get it to display what I want when it is expanded with the text from each column aligned along the top. 当它展开时,它显示了我想要的内容,并且每一列的文本都沿着顶部对齐。

The issue with this is that when resized to a small size it displays it like it is shown here where as I want it to display as the hardware section does. 问题在于,当将其调整为较小尺寸时,它会像在此处显示的那样显示它,就像我希望它在硬件部分显示的那样。

So here is my question: Is there a way with bootstrap to get it to display how I want it in both cases or do I have to choose one or the other? 所以这是我的问题:在两种情况下,bootstrap是否有办法显示我想要的方式,还是我必须选择其中一种?

尝试将col-md-x更改为col-xs-x

Use a media query to only apply the centering styles on larger widths. 使用媒体查询仅将居中样式应用于较大的宽度。 The margin of the h3 is effecting the vertical alignment so you may want to adjust that. h3的边距影响垂直对齐,因此您可能需要对其进行调整。 Also IMO, flexbox is a better alignment method... 同样是IMO,flexbox是更好的对齐方式...

@media (min-width:768px) {
    .flex {
        display:flex;
        align-items:center;
    }
    h3 {
        margin-top:5px;
    }
}

http://www.codeply.com/go/hR8GJDwdL1 http://www.codeply.com/go/hR8GJDwdL1

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

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