【问题标题】:Vertical align centre and matching heights in BootstrapBootstrap中的垂直对齐中心和匹配高度
【发布时间】:2020-10-15 05:42:42
【问题描述】:

我正在尝试在 Bootstrap 中进行一些垂直对齐,但似乎无法通过各种弹性框类(align-items-center 等)实现它。

我需要以下代码笔框中的文本内容垂直居中...同时每个框也应与最高框的高度匹配(目前正在工作)...有人可以帮忙吗?!

内部 div 需要包含在链接中 - 不知道这是否会影响事情?

https://codepen.io/jwacreative/pen/VwjePEj

<div class="container">
<div class="row">
  <div class="col-md-6 col-lg-4 mb-4">
  <a href="http://">
    <div class="summary-box h-100" style="background:red">
      <h2>Title</h2>
      <p>Some text</p>
    </div>
  </a>
  </div>
  <div class="col-md-6 col-lg-4 mb-4">
  <a href="http://">
    <div class="summary-box h-100" style="background:green">
      <h2>Title</h2>
      <p>Some text longer text Some text longer text Some text longer text Some text longer text Some text longer text Some text longer text<< /p>
    </div>
  </a>
  </div>
  <div class="col-md-6 col-lg-4 mb-4">
    <div class="summary-box h-100" style="background:blue">
      <h2>Title</h2>
      <p>Some text</p>
    </div>
  </div>
</div>

【问题讨论】:

    标签: css twitter-bootstrap bootstrap-4


    【解决方案1】:

    CSS Grid 应该能够帮助解决这个问题...

    .summary-box {
      display: grid;
      align-content: center;
    }
    

    【讨论】:

    • 太棒了——由于兼容性,我以前从未使用过“网格”,所以并没有真正意识到这个解决方案——但我认为在这种情况下,它不垂直居中的后备是完全可以接受的!
    猜你喜欢
    • 2013-11-10
    • 1970-01-01
    • 2018-04-21
    • 2018-08-23
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多