Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsive image align center bootstrap 3

I do a catalog using Bootstrap 3. When displayed on tablets, the product images look ugly because of their small size (500x500) and a width of 767 pixels in the browser. I want to put the image in the center of the screen, but for some reason I can not. Who be will help solve the problem?

Screenshot of part of a product page with the product not centered underneath the headline

like image 475
Konstantin Rusanov Avatar asked Aug 27 '13 10:08

Konstantin Rusanov


People also ask

How do I center align items 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.

How do I center an image in responsive?

Answer: Use the center-block Classcenter-block on it, along with the . img-responsive class in Bootstrap 3. The . center-block class is however removed in Bootstrap 4, but you can still achieve the same effect using the classes .

How do I center align an image in Bootstrap?

Aligning images block -level images can be centered using the .mx-auto margin utility class.


2 Answers

There is .center-block class in Twitter Bootstrap 3 (Since v3.0.1), so use:

<img src="..." alt="..." class="img-responsive center-block" /> 
like image 115
DHlavaty Avatar answered Sep 19 '22 21:09

DHlavaty


If you're using Bootstrap v3.0.1 or greater, you should use this solution instead. It doesn't override Bootstrap's styles with custom CSS, but instead uses a Bootstrap feature.

My original answer is shown below for posterity


This is a pleasantly easy fix. Because .img-responsive from Bootstrap already sets display: block, you can use margin: 0 auto to center the image:

.product .img-responsive {     margin: 0 auto; } 
like image 45
Bojangles Avatar answered Sep 20 '22 21:09

Bojangles