0

我试图<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());  
});
4

2 回答 2

0
div {
   position:relative;
}
div img {
   position:absolute; 
   top:0; left:0; right:0; bottom:0;
}
于 2013-01-19T01:47:58.523 回答
0

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

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

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

img {
    width:100%;
    height:100%;
}
于 2013-01-19T01:26:59.223 回答