在引导卡头中垂直对齐

时间:2018-03-21 16:54:54

标签: css twitter-bootstrap

我正在尝试使用boostrap4来创建卡片标题,其中标题是卡片标题的文本对齐中心,右对齐的icone 并且都垂直居中

我尝试了一些东西但似乎没有达到我想要的东西;

++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                                                    +
+                        title                  icone+
+                                                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++

代码:

<div class="card-header text-center bg-dark text-white">
            <div class="row h-100">
              <div class="col-md-11">
                <h5>Complete models list</h5>
              </div>
              <div class=col-md-1>
                <i class="far fa-question-circle float-right align-self-center"></i>
              </div>
            </div>

          </div>

任何想法如何让它发挥作用?

1 个答案:

答案 0 :(得分:5)

align-items-center ...

上使用row
 <div class="card-header text-center bg-dark text-white">
      <div class="row align-items-center">
             <div class="col-md-11">
                    <h5>Complete models list</h5>
             </div>
             <div class="col-md-1">
                   <i class="fa fa-question-circle float-right"></i>
             </div>
      </div>
 </div>

或者<h5>的死点,同时保持图标右对齐,使用带有自动边距(d-flex align-items-center)的ml-auto div来推送右边的图标......

<div class="card">
       <div class="card-header text-center bg-dark text-white">
             <div class="d-flex align-items-center">
                  <h5 class="mx-auto w-100">Complete models list</h5>
                  <i class="fa fa-question-circle ml-auto"></i>
             </div>
       </div>
       <div class="card-body">
             <p class="text-center">center</p>
       </div>
 </div>

Demo of both options