div里面的图片超出div的宽度,自动调整大小。

来源:互联网 发布:js多级联动下拉菜单 编辑:程序博客网 时间:2024/05/16 16:10

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#pic{ margin:0 auto; width:740px; padding:0;} 
#pic img{ max-width:740px; width:expression_r(document.body.clientWidth>document.getElementByIdx_x_x("pic").scrollWidth*9/10? "740px": "auto" );}
</style>
</head>
<body>
    <div id="pic" style="width:740px;">
        <img id="img" src="http://f.hiphotos.baidu.com/image/pic/item/bd3eb13533fa828bd30590f5fe1f4134970a5a85.jpg" alt="" runat=server/>
    </div>
</body>
</html>

测试谷歌 ie8、10都能用。


0 0