Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap 3, vertically center content [duplicate]

I know this has been asked a thousand time but I can't find a way to make the text and image to be centered vertically.

I'm using Twitter Bootstrap 3 with dynamic content so therefor, I do not know the size on neither the text nor the image. Plus, I want it all to be responsive.

I've created a bootply that summarize the kind of layout I'm trying to achieve. Basically, I want the text and image to be vertically centered. The text is not always bigger than the image.

Can someone help me out with this please?

Thank you.

like image 803
Jacques Bourque Avatar asked Nov 15 '13 16:11

Jacques Bourque


People also ask

How do I vertically align text in Bootstrap 3?

row is now display:flex you can simply use align-self-center on any column to vertically center it... or, use align-items-center on the entire . row to vertically center align all col-* in the row...

How do I center something vertically in bootstrap?

1 — Vertical Center Using Auto Margins 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 do I center content in Bootstrap 3?

By adding the ” text-center” class of Bootstrap 3 We can use the “text-center” class of bootstrap 3 for the center-alignment of an element. So in our td when we add “text-center” class, and then our table text goes to the center.


2 Answers

You can use display:inline-block instead of float and vertical-align:middle with this CSS:

.col-lg-4, .col-lg-8 {     float:none;     display:inline-block;     vertical-align:middle;     margin-right:-4px; } 

The demo http://bootply.com/94402

like image 94
DaniP Avatar answered Oct 22 '22 01:10

DaniP


Option 1 is to use display:table-cell. You need to unfloat the Bootstrap col-* using float:none..

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

http://bootply.com/94394


Option 2 is display:flex to vertical align the row with flexbox:

.row.center {    display: flex;    align-items: center; } 

http://www.bootply.com/7rAuLpMCwr


Vertical centering is very different in Bootstrap 4. See this answer for Bootstrap 4 https://stackoverflow.com/a/41464397/171456

like image 25
Zim Avatar answered Oct 22 '22 00:10

Zim