tags:

views:

38

answers:

3

imax is a div element.

#imax {
width:222px;
height:222px;
}
#imax img {
width:222px;
height:auto;
}

if either way I tried auto on width or height, the images with different orientation will result in distort in either scale. How could I fix to display with ratio-aspect?

A: 

Cannot be done with CSS only.

You could use Javascript to do this: Get either height or width of the full size image, then calculate the correct smaller size.

Arve Systad
+2  A: 

Leave out the height:

#imax img {
  width:222px;
}

And the browser will take care of the aspect ratio calculation.

Gert G
but the portrait image would overlap to the bottom.
proyb2
You'll have to decide which direction you want fixed. If you want the height fixed, then you set the height, but leave out the width.
Gert G
+2  A: 

The image is distorted since you put restrictions on it's parent. If you specify just one of the size attributes, the other should scale according to proportions - unless it's limited/affected by its container. Might work differently if you used max-height/width on the container

Eran Galperin