CSS image resize percentage of itself?

前端 未结 11 2167
执念已碎
执念已碎 2020-11-28 20:46

I am trying to resize an img with a percentage of itself. For example, I just want to shrink the image by half by resizing it to 50%. But applying width: 50%; w

11条回答
  •  悲哀的现实
    2020-11-28 21:22

    I think you are right, it's just not possible with pure CSS as far as I know (not cross-browser I mean).

    Edit:

    Ok I didn't like my answer very much so I puzzled a little. I might have found an interesting idea which could help out.. maybe it IS possible after all (although not the prettiest thing ever):

    Edit: Tested and working in Chrome, FF and IE 8&9. . It doesn't work in IE7.

    jsFiddle example here

    html:

    css:

    #img_wrap {
        display: inline-block;       
        position:relative;    
    }
    
    #rescaled_img_wrap {
        width: 50%;
    }
    #original_img {
        display: none;
    }
    #rescaled_img {
        width: 100%;
        height: 100%;
    }
    

提交回复
热议问题