Internet Explorer会自动将高度和宽度属性添加到新添加的图像中 [英] Internet Explorer adds height- and width-attributes to a newly appended image automatically

查看:107
本文介绍了Internet Explorer会自动将高度和宽度属性添加到新添加的图像中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将新创建的图像加载到DOM后附加:

I append a newly created image after it has been loaded to the DOM:

var i = $('<img/>');
i[0].src = 'http://placehold.it/700x300';
i.attr('alt', '');
i.on('load', function() {
    $('body').append(i);            
});






我为图片设置了固定的高度CSS:


I have set a fixed height for the images in CSS:

img {
    height: 150px;
}






不幸的是,Internet Explorer添加了 width - 和 height - 属于图像,因此它会严重失真。我怎么能阻止这个?我追加元素后是否必须手动删除属性?


Unfortunately the Internet Explorer adds the width- and height-attributes to the image so it gets heavily distorted. How can I prevent this? Do I have to manually remove the attributes after I append the element?

jsFiddle链接

推荐答案

试试这个:

img {
    height: 150px;
    width: auto;
}

这篇关于Internet Explorer会自动将高度和宽度属性添加到新添加的图像中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆