Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically Center Text Bootstrap

I wanted to center vertically my text inside a

div class="col-md-6"

and have the same height

Example:

...

like image 297
NeptuneZ Avatar asked May 26 '17 11:05

NeptuneZ


People also ask

How do I center content vertically in bootstrap?

Answer: Use the align-items-center Class In Bootstrap 4, if you want to vertically align a <div> element in the center or middle, you can simply apply the class align-items-center on the containing element.

How do I center text vertically and horizontally in bootstrap 5?

To center div both vertically and horizontally use flexbox utilities. See the examples. Add d-flex align-items-center justify-content-center classes to the parent element to center its content vertically and horizontally.

How do I center text in a column in bootstrap?

You can add float:none; margin:auto; styling to centerize column content.

How do I vertically center text in a div?

Answer: Use the CSS line-height property Suppose you have a div element with the height of 50px and you have placed some link inside the div that you want to align vertically center. The simplest way to do it is — just apply the line-height property with value equal to the height of div which is 50px .


2 Answers

this is bootstrap 4:

<html><head>    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
<div class="row">
<div class="col-6">
    <img src="https://media.haircutinspiration.com/photos/20181204011855/boy-hairstyle-e1536810585307.jpg" class="img-fluid">
</div>
    <div class="col-6 align-self-center">
        hello hello
    </div>

</div>
  </body>
like image 200
Wria Mohammed Avatar answered Oct 20 '22 19:10

Wria Mohammed


Check my snippet it will work as you want ...

.content_center {
  display: flex;
  justify-content: center;
  align-items: center; 
  width: 250px;
  height: 150px;
  border : 1px solid black;
}
<div class="content_center col-md-6">
What I want
</div>
like image 43
Mohideen bin Mohammed Avatar answered Oct 20 '22 18:10

Mohideen bin Mohammed