I'm working on a thumbnail page for an image gallery. Thumbnail previews are done as an <ul>
with floating <li>
with a fixed, square size.
The thumbnails images themselves however are not necessarily square or same size, they have the properties of the large images they represent.
To make it look nice I'd like to display the center of the thumbnail image in the square <li>
, cutting off an equal amount of overflow left and right (see fig. 1):
+..+---------+..+ +---------+....+ ://| /\_/\ |//: | /\_/|////: ://| ( o.o ) |//: | ( o.o|////: ://| > ^ < |//: | > ^ |////: ://| {o___o} |//: | {o___|////: +..+---------+..+ +---------+....+ (fig. 1) (fig. 2)
I can do this by removing the <img>
tag and defining (CSS sprite):
<li style="width: x; height: x; overflow: hidden;">
<div style="background: url(...) no-repeat center center;"/>
</li>
This works and looks nice but only when you have CSS enabled. Plus it's not very semantic since the image is not displayed by an <img>
tag.
When I use an <img>
tag in place of the inner <div>
above, things look more like in fig. 2.
How would I move the <img>
via CSS to always be centered, no matter how wide the thumbnail image actually is? I assume some sort of relative positioning might do it, but a naïve position: relative; left: -50%;
does not work.
P.S.: Yes, I know that I could make all the thumbnails square, assume that this is not the answer I'm looking for.