Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center image in container element with fixed size (CSS, HTML)

Tags:

html

css

I want to display images on a .net page which I load from database (the amount can thus vary). All images have different widths and heights up to 130px and 60px respectively. I want to put the images into container elements with a fixed width of 130px and a fixed height of 60px. The images should be centered vertically and horizontally. The container elements should be aligned horizontally if possible.

I tried div (with float) and span. With div, I get the fixed sizes, but cannot center the images. With span, I can center, but not set any size. If I put span into div, it seems to behave like div (centering is ignored).

like image 518
AGuyCalledGerald Avatar asked Mar 28 '12 16:03

AGuyCalledGerald


1 Answers

With Bootstrap 3 you can add an img-responsive center-block class to center an image

<img class="img-responsive center-block" src="my_image.png" />
like image 78
Dan Nick Avatar answered Sep 19 '22 12:09

Dan Nick