Using CSS how can I center an image of unknown dimensions?
img {display:block; margin: 0 auto}
or
.container {text-align:center}
/* container must contain some text as well */
.container, img {line-height:100px; vertical-align:middle}
or
.container {display:table-cell; vertical-align:middle}
.container {background: url(…) 50%;}
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.
You can use CSS like this:
img { display: block; margin: 0 auto; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With