阻止图片超过DIV的宽度,实现方式如下
CSS
img{max-width:100%;margin-left:-1em;text-align:center;text-indent:0;}
<script> function $(id) { return document.getElementById(id); } function autoResizepic() { var bodywidth = $('fontzoom').style.width; bodywidth =document.body.scrollWidth var picTarget=$('fontzoom').getElementsByTagName('img'); if(picTarget.length>0) { for(var i =0;i<picTarget.length;i++) { if(picTarget[i].width>bodywidth) {picTarget[i].width=bodywidth-50;} if(picTarget[i].width<bodywidth) {picTarget[i].width=bodywidth-50;} } } } window.onresize=autoResizepic; </script>