2

Every time I work on a new project I do not have any problems to center the text using "text-align: center" to center the text, but I have never seen a similar code to center images so I always have hack the code by either centering the images in the HTML (not the cleanest option) or by giving the image a variable width (which does not work on multiple resolutions). Is there any way to accomplish this that I have not tried? And, does any one know if something like this will be implemented in CSS3?

2
  • I dont think so but what I do Is in my HTML file I will add: <center><img src="example.png"/></center>
    – megubyte
    Aug 9, 2010 at 20:33
  • 3
    I think this belongs on DocType. Aug 9, 2010 at 20:46

2 Answers 2

8

Set the containing elements style to

text-align:center;

set your image style to

display:inline-block;
margin:auto;
2

Sruly's answer hits the nail on the head. the only thing I would consider adding is vertical-align: middle; for the image tag, as follows:

display:inline-block;
margin:auto;
vertical-align: middle;

Not the answer you're looking for? Browse other questions tagged or ask your own question.