Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I vertically and horizontally center text in a container in bootstrap 4?

Let's say I want to center the h1 and p elements in the division.

<div id="outer" class="container">
 <div id="inner">
  <h1>Heading</h1>
  <p>Some content</p>
 </div>
</div>
like image 404
Christopher Dias Avatar asked Dec 23 '22 12:12

Christopher Dias


1 Answers

It is very easy makes the parent div as display: flex and make the child element margin: auto;

Check the demo below.

#outer {
  width: 100%;
  height: 100vh;
  display: flex;
}

#inner {
  margin: auto;
}
<div id="outer" class="container">
  <div id="inner">
    <h1>Heading</h1>
    <p>Some content</p>
  </div>
</div>
like image 182
Rajendran Nadar Avatar answered Dec 26 '22 19:12

Rajendran Nadar