tags:

views:

21

answers:

1

I am trying to resize an image using only CSS, the problem is I don't know it's dimensions.

What I have tried so far is putting the into a and then making the image have 105% width. The idea was that the containing div would have no size other than it's contents, but this is only make the image the size of the next ancestor that does have an explicit size.

A: 

In order to resize something in CSS you have to either give it an exact pixel value or base the size on something else.

If you were to set an image to have a width of 105% of its container then that container must have some width for you to use. If it's a regular div with no styling applied then its width will be the full width of that divs parent and your img will be 105% of that.

If the div holding the img is floated then it will be getting its width from its contents (aka the img). This won't work because you can't have two elements getting their widths from each other. One of them has to be constrained somehow.

Christian Schlensker