Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use vertical align in bootstrap

Simple problem: How do I vertically align a col within a col using bootstrap? Example here (I want to vertically align child1a and child1b):

http://bootply.com/73666

HTML

<div class="col-lg-12">    <div class="col-lg-6 col-md-6 col-12 child1">     <div class="col-12 child1a">Child content 1a</div>     <div class="col-12 child1b">Child content 1b</div>    </div>     <div class="col-lg-6 col-md-6 col-12 child2">   Child content 2<br>   Child content 2<br>   Child content 2<br>   Child content 2<br>   Child content 2<br>    </div>  </div> 

UPDATE

Some CSS:

.col-lg-12{ top:40px; bottom:0px; border:4px solid green;   }    .child1a, .child1b{   border:4px solid black;   display:inline-block !important; }  .child1{   border:4px solid blue;   height:300px;   display:table-cell !important;   vertical-align:middle; }  .child2{   border:4px solid red; } 
like image 407
alias51 Avatar asked Aug 12 '13 16:08

alias51


People also ask

How do I vertically align an item in bootstrap?

One way to vertically center is to use my-auto . This will center the element within it's flexbox container (The Bootstrap 4 . row is display:flex ). For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column.

How vertically align columns in bootstrap?

In Bootstrap 5, if we want to vertically align an <div> element in the middle of a containing element, we can do this by applying the class align-items-center and d-flex on the containing element of that div. Here, the d-flex class has the same effect as that of the display: flex; property in CSS.

How do I vertically align text in bootstrap 5?

Aligning content to the center of the DIV is very simple in Bootstrap 5, You just have to convert the div into a flex box using d-flex class property and then use the property align-items-center to vertically align the content in the middle of the div.

How do I vertically align a div in bootstrap 4?

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.


2 Answers

.parent {     display: table;     table-layout: fixed; }  .child {     display:table-cell;     vertical-align:middle;     text-align:center; } 

table-layout: fixed prevents breaking the functionality of the col-* classes.

like image 143
magirtopcu Avatar answered Sep 28 '22 07:09

magirtopcu


Maybe an old topic but if someone needs further help with this do the following for example (this puts the text in middle line of image if it has larger height then the text).

HTML:

<div class="row display-table">     <div class="col-xs-12 col-sm-4 display-cell">         img     </div>     <div class="col-xs-12 col-sm-8 display-cell">         text     </div> </div> 

CSS:

.display-table{     display: table;     table-layout: fixed; }  .display-cell{     display: table-cell;     vertical-align: middle;     float: none; } 

The important thing that I missed out on was "float: none;" since it got float left from bootstrap col attributes.

Cheers!

like image 31
prinsen Avatar answered Sep 28 '22 07:09

prinsen