Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center the content inside a column in Bootstrap

I Need help to fix the problem, I need to center the content inside the column in bootstrap4, please find my code below

<div class="container">     <div class="row justify-content-center">         <div class="col-3">         <div class="nauk-info-connections">         </div>      </div> </div> 
like image 853
Praveen Kumar Avatar asked Mar 01 '17 09:03

Praveen Kumar


People also ask

How do you center elements in a column?

To center the items within a column, we use align-items and justify-items instead of the align-content and justify-content in our previous example. Using the item properties, we can align our items just like we did with our columns.

How do I center text in Bootstrap?

Add class . text-center to the parent div to align text or any item inside to the center. You can also decide how the alignment should look like on the specific screen sizes.

How do I center a div in a column?

you can use col-md-4 col-md-offset-4. it is center column.


1 Answers

Bootstrap 5 (update 2021)

Since flexbox is still used the centering methods in Bootstrap 5 work the same way. Columns can be centered using offset, auto-margins or justify-content-center (flexbox).

Demo of the Bootstrap 5 Centering Methods

Bootstrap 4 (original answer)

There are multiple horizontal centering methods in Bootstrap 4...

  • text-center for center display:inline elements
  • offset-* or mx-auto can be used to center column (col-*)
  • or, justify-content-center on the row to center columns (col-*)
  • mx-auto for centering display:block elements inside d-flex

mx-auto (auto x-axis margins) will center display:block or display:flex elements that have a defined width, (%, vw, px, etc..). Flexbox is used by default on grid columns, so there are also various flexbox centering methods.

Demo of the Bootstrap 4 Centering Methods

In your case, use mx-auto to center the col-3 and text-center to center it's content..

<div class="row">     <div class="col-3 mx-auto">         <div class="text-center">             center         </div>     </div> </div> 

https://codeply.com/go/GRUfnxl3Ol

or, using justify-content-center on flexbox elements (.row):

<div class="container">     <div class="row justify-content-center">         <div class="col-3 text-center">             center         </div>     </div> </div> 

Also see:
Vertical Align Center in Bootstrap

like image 136
Zim Avatar answered Sep 16 '22 23:09

Zim