0

How to vertically and horizontally center text inside both the columns? I'm using bootstrap 4.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">

<div class="row">

  <div class="col">
    <h1>
      <p> hello hello hello hello hello hello hello hello hello hello hello hello
      </p>

    </h1>

  </div>
  <div class="col">
    <p> hello hello hello hello hello hello hello hello hello hello hello hello
    </p>
  </div>
</div>
mplungjan
  • 155,085
  • 27
  • 166
  • 222
uitwaa
  • 585
  • 1
  • 10
  • 22

3 Answers3

3

Use "display: flex" property and apply these...

To align content horizontally justify-content: center;

To align content vertically align-items: center;

.col {
    display: flex;
    justify-content: center;
    align-items: center;
}
Mohideen bin Mohammed
  • 16,635
  • 8
  • 97
  • 110
2

This what you need? Having height for row would visualize better.

.col {
  display: flex;
  justify-content: center;
  align-items: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<div class="row">
  <div class="col">
    <h1>
      <p> hello hello hello hello hello hello hello hello hello hello hello hello
      </p>
    </h1>
  </div>
  <div class="col">
    <p> hello hello hello hello hello hello hello hello hello hello hello hello
    </p>
  </div>
</div>
Gerard
  • 14,447
  • 5
  • 28
  • 48
0

You can use the flexbox properties via dedicated class:

https://v4-alpha.getbootstrap.com/utilities/flexbox/#align-items

Align items

Use align-items utilities on flexbox containers to change the alignment of flex items on the cross axis (the y-axis to start, x-axis if flex-direction: column). Choose from start, end, center, baseline, or stretch (browser default).

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">

<div class="row">

  <div class="col d-flex align-items-center ">
    <h1>
      <p> hello hello hello hello hello hello hello hello hello hello hello hello
      </p>

    </h1>

  </div>
  <div class="col d-flex align-items-center">
    <p> hello hello hello hello hello hello hello hello hello hello hello hello
    </p>
  </div>
</div>
Community
  • 1
  • 1
G-Cyrillus
  • 94,270
  • 13
  • 95
  • 118