使用图像填充div(忽略比例)

时间:2013-01-19 01:19:05

标签: javascript jquery html css image

我试图用图片填充父<div>,同时完全忽略比例。我知道它在某些方面看起来很难看,我只想看看它是否可能。如您所见,图像正在缩放,而不是延伸到我的要求(Chrome):http://jsfiddle.net/qdzaw/61/

不幸的是,我在网上找到的就是如何在保持比例的同时做到这一点:/

<img class="someimage" src="imgsrc" />

$(window).resize(function() {
    $(".someimage").height($(".someimage").parent().height());     
    $(".someimage").width($(".someimage").parent().width());  
});

2 个答案:

答案 0 :(得分:0)

我想我在这篇文章中找到了答案:Stretch and scale a CSS image in the background - with CSS only

使用父div元素和此样式表:

div {
    width: 100%; 
    height: 100%; 
}

img {
    width:100%;
    height:100%;
}

答案 1 :(得分:0)

div {
   position:relative;
}
div img {
   position:absolute; 
   top:0; left:0; right:0; bottom:0;
}