Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Vertical Align Image

Tags:

On this website: http://www.livenews.surf/ I want to make news images and text vertically middle align, how i can do that?

like image 430
Gonçalo Loureiro Avatar asked May 11 '16 08:05

Gonçalo Loureiro


People also ask

How do I vertically align an image 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 an image in Bootstrap 4?

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 you vertically align elements 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.


2 Answers

Use the following classes in your containing div.row instead of custom CSS as suggested for bootstrap 4.

d-flex flex-wrap align-items-center

like image 117
jcaruso Avatar answered Oct 21 '22 12:10

jcaruso


The easiest solution is to use Flexbox (see spec. for more details on it's usage).

For this particular case, assign a custom class to each of your content containing div (currently it only has .col-md-11), for example class "content" and add this code to your stylesheet

.content {     display: flex;     align-items: center;     flex-wrap: wrap; } 

Small code explanation: align-items aligns the items vertically, since we left the default flex direction which is row and flex-wrap will allow our parent container to wrap children to next line (default is nowrap).

Keep in mind, that I haven't included vendor prefixes for the sake of this answer, however I would strongly recommend you to do so, using a tool such as Autoprefixer.

like image 28
Leo Napoleon Avatar answered Oct 21 '22 13:10

Leo Napoleon