Using CSS how can I center an image of unknown dimensions?
+4
A:
Seeing as images are native inline-block
elements (I think - at least not block
),
text-align: center
for the surrounding container will do the job.
Pekka
2010-06-06 19:43:46
+2
A:
You can use CSS like this:
img { display: block; margin: 0 auto; }
Martti Laine
2010-06-06 19:45:45
+6
A:
Horizontally
img {display:block; margin: 0 auto}
or
.container {text-align:center}
Vertically
/* container must contain some text as well */
.container, img {line-height:100px; vertical-align:middle}
or
.container {display:table-cell; vertical-align:middle}
If image is only decorative:
.container {background: url(…) 50%;}
porneL
2010-06-06 19:49:31
+1 for thinking about horizontally and vertically.
Pekka
2010-06-06 19:51:03