开发者

resizing an unknown image size using CSS?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜