So I have a div like
.div{
width:78px;
height:78px;
overflow: hidden;
position: relative;
float: left;
}
I want to put random images inside that div, I dont know the image dimensions.
If the image is bigger than the div , the image should get cropped and then centered in that div. And has to keep its aspect ratio.
I have to do this without CSS3.
I tried position absolute , display block and then add top and left and then minus the same amount of pixels in margin.
top:50%;
left:50%;
margin-top:-50%;
margin-left:-50%;
I tried display block and margin left, margin right : 0 auto. I tried without the position absolute. I put float. I removed it. I dont know how to do it.
Please advice.
Here is a fiddle.
In the fiddle I should see the X centered and the 600 and 400 would be half outside the div. But at best, I see the 600 and the X. So the image preserves the ratio, gets cropped but cannot align it.
EDIT
I would like to do this without using the background property at all. Just the img.
Thanks