I have two div's:
<div class="iphonebackground">
<div class="screenbackground"></div>
</div>
.iphonebackground {
background-image:url("../img/iphone-frame.png");
background-repeat: no-repeat;
background-position: center;
background-size: 100%;
height:576px;
}
.screenbackground {
background-image:url("../img/iphone-background.png");
background-repeat: no-repeat;
background-position: center;
background-size:100%;
height:576px;
}
首先,iphonebackground的背景图像设置为iPhone框架的图像(http://chpwn.com/apps/iphone-frame.png)。其次,screenbackground的背景图像设置为PNG图像,与屏幕图片尺寸相同(https://dl.dropbox.com/u/290586/iphone-bg.png)。
结果是使页面呈现出如下内容:http://imgur.com/yVF9gyg。由于我的网站基于Twitter Bootstrap,div会调整大小以适应浏览器窗口大小,因此在较小的显示器上,它看起来像这样:http://imgur.com/Q2Qy4wn。
正如您所见,div的高度固定为576px。这意味着在第二张图片中,背景图像的上方和下方有很多空白空间。是否有一种方法可以将div的高度设置为背景图像高度的大小,从而消除空白空间?