Bootstrap 4 vertically center text in div

前端 未结 3 1515
孤独总比滥情好
孤独总比滥情好 2021-01-14 06:52

I have this simple HTML code (with Bootstrap) :

相关标签:
3条回答
  • 2021-01-14 07:21

    You can used Flex box predefine class in Bootstrap for that:

    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
    <div id="accordion">
      <div class="card ">
        <div class="card-header" id="@itm.Id">
          <div class="row">
            <div class="col-2 border rounded justify-content-center  d-flex align-items-center">
              text to center
            </div>
            <div class="col-2 border rounded text-center">                           ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
            </div>
          </div>
        </div>
      </div>
    </div>

    For Information you can read here.

    0 讨论(0)
  • 2021-01-14 07:32

    Try adding my-auto to the first div inside the row.

    <div class="col-2 border rounded text-center my-auto">
    

    https://jsfiddle.net/7zm40xj9/7/

    0 讨论(0)
  • 2021-01-14 07:34

    Please Use Class: justify-content-center

    0 讨论(0)
提交回复
热议问题