.img { margin-left: auto; margin-right: auto; width: 8em; }
<div class="img"><img src="xbox.jpg" width="273" height="211" /><img src="wii.jpg" width="408" height="312" /></div>
.img { margin-left: auto; margin-right: auto; width: 8em;}
.img { text-align: center;}
vertical-align
.img img { vertical-align: middle; /* bottom, top, or any of the other options */}
jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px"); this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px"); return this;}// Now we can just write:$(element).center();
And the HTML...
with:
Then, if you want to adjust their vertical alignment, you can do so with the
vertical-alignproperty:I apologize for the hijack
The upside is that you don't need to use any extra markup, the downside is that it won't work in IE7.
I found this
Solved: Result
It's not as flexible as what you are currently using, but it is less code for a single image.
http://jsfiddle.net/joshnh/Ff5hm/