views:

37

answers:

1

So, I want to have an image resized to 30% of its original height/width. Pretend you don't know its height or width, how would you go about it using only CSS/HTML?

+3  A: 

Sadly no pure HTML/CSS way to do it as neither is geared to perform calculations like that. However, it's pretty simple with a snippet of jQuery:

$('img.toResizeClass').each(function(){
    var imgWidth = $(this).width();
    var imgHeight = $(this).height();

    if(imgWidth > imgHeight){
        $(this).width(imgWidth * 0.3);
    } else {
        $(this).height(imgHeight * 0.3);
    }
});
Pat
thank you, very very useful
PizzaPie