我有一张大图作为页面的background-image
。我想让图片的高度拉伸以填充页面的高度,同时也要居中显示。
background: black url("/image/background.jpg") no-repeat fixed center;
我有一张大图作为页面的background-image
。我想让图片的高度拉伸以填充页面的高度,同时也要居中显示。
background: black url("/image/background.jpg") no-repeat fixed center;
这里有一篇很好的文章:
http://css-tricks.com/perfect-full-page-background-image/
其要点是:
body {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
{
background: black url("/image/background.jpg") no-repeat fixed center;
height: 100%;
width:100%
}
我认为使用 div 是实现你想要的效果最简单的方法。
<div id="background">
<img src="/image/background.jpg" class="stretch" alt="" />
</div>
<style>
#background {
background-color:#000000;
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -1;
}
.stretch {
width:100%;
height:100%;
}
</style>
background-size: 1024px 100%;
。 - JR Galia