我有这个标记:
<div class="img_container">
<img src="file://localhost/img/a_bg.jpeg" alt="a_bg" />
</div>
如何将图像的宽度和高度应用到img_container?
图像位于绝对位置
最佳答案
未经测试,但我建议:
$('.img_container img').each(function(){
var w = this.naturalWidth,
h = this.naturalHeight;
$(this).parent().css({'height': h, 'width' : w});
});
关于javascript - 将子图像的宽度和高度应用于容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15345926/