I have been trying to sort out how to center an oversized image within a div using css only.
We are using a fluid layout, so the width of the image containers varies
Put a large div inside the div, center that, and the center the image inside that div.
This centers it horizontally:
HTML:
CSS:
.imageContainer {
width: 100px;
height: 100px;
overflow: hidden;
position: relative;
}
.imageCenterer {
width: 1000px;
position: absolute;
left: 50%;
top: 0;
margin-left: -500px;
}
.imageCenterer img {
display: block;
margin: 0 auto;
}
Demo: http://jsfiddle.net/Guffa/L9BnL/
To center it vertically also, you can use the same for the inner div, but you would need the height of the image to place it absolutely inside it.