Bootstrap: img.img-responsive wrapped in div.center-block does not align

Created on 14 Nov 2013  路  2Comments  路  Source: twbs/bootstrap

The css of the following html needs to be fixed as shown below:
HTML:

<div class="center-block">
<img src="img/file.png" class="img-responsive" alt="Responsive Image">
</div>

CSS-FIX:

.center-block .img-responsive {margin: 0 auto;}
css

Most helpful comment

I believe you're supposed to put that on the image

<img src="img/file.png" class="img-responsive center-block" alt="Responsive Image">

http://bootply.com/94007

.center-block {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

If .center-block was supposed to be a wrapper, it would have a text-align:center inside it, I would think.

All 2 comments

I believe you're supposed to put that on the image

<img src="img/file.png" class="img-responsive center-block" alt="Responsive Image">

http://bootply.com/94007

.center-block {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

If .center-block was supposed to be a wrapper, it would have a text-align:center inside it, I would think.

Yup, use it on the element that is meant to be centered.

Was this page helpful?
0 / 5 - 0 ratings