How to auto resize the image for responsive design with pure css?

前端 未结 8 1866
挽巷
挽巷 2021-02-14 16:42

I have tried to auto resize the image using the CSS property max-width, but it does\'t work in IE7 and IE8. Is there any way to auto resize the image with pure CSS

8条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 16:56

    You need a one-time cached expression for IE 6-7.

    IMG {
    zoom:expression(
        function(t){
            t.runtimeStyle.zoom = 1;
            var maxW = parseInt(t.currentStyle['max-width'], 10);
            var maxH = parseInt(t.currentStyle['max-height'], 10);
            if (t.scrollWidth > maxW && t.scrollWidth >= t.scrollHeight) {
                t.style.width = maxW;
            } else if (t.scrollHeight > maxH) {
                t.style.height = maxH;
            }
        }(this)
    );
    }
    

    Example: http://kizu.ru/lib/ie/minmax.html JS source file: http://kizu.ru/lib/ie/ie.js

    Author: Roman Komarov

提交回复
热议问题