Hello everybody, like the subject line suggests, I’m trying to force a div that contains an image to shrink to the image’s dimensions, in order to centralize the image inside the containing div. For the sake of simplicity, I’m going to henceforth refer to the container div as outer div and the image as inner div.
Normally I would use this line within the inner div style to force inner div to centralized within outer div:
#inner_div{width: some fixed number; margin-left: auto ; margin-right: auto ;}
But in this case, the inner div has no fixed width. I set a fixed height and a max-width so that the picture can wouldn’t be stretched and distorted. Then in the outer div, I set overflow to hidden to hide any extra height from being displayed. Pictures where the width exceeds the height look like this which is exactly what i want:
But when the height exceeds the width, then arises the need for the image to be centralized and apparently the max-width attribute prevents the image to be centralized.
So I figured out that the solution would be to shrink the outer div to assume the width of inner div, then centralize outter div within its own container div. I’m not sure how shrinking to fit can be accomplished. Any ideas? Or any other smart ideas to fix the original problem?