CSS拉伸背景图像

CSS拉伸背景图像,css,Css,我有一个大图像要用作页面的背景图像。我想要的是图像的高度将被拉伸以填充页面的高度。它也应该居中 background: black url("/image/background.jpg") no-repeat fixed center; 将此添加到css中 { background: black url("/image/background.jpg") no-repeat fixed center; height: 100%; width:100% } background size:cov

我有一个大图像要用作页面的
背景图像。我想要的是图像的高度将被拉伸以填充页面的高度。它也应该居中

background: black url("/image/background.jpg") no-repeat fixed center;
将此添加到css中

{
background: black url("/image/background.jpg") no-repeat fixed center;
height: 100%;
width:100%
}

background size:cover
将在现代浏览器中发挥作用-有关详细信息,请参阅mozilla的


对于较旧的浏览器(尤其是IE的较旧版本),我已经在jQuery插件上取得了很多成功,这些插件喜欢模仿这种行为。

我认为使用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>

#背景{
背景色:#000000;
宽度:100%;
身高:100%;
位置:固定;
左:0px;
顶部:0px;
z指数:-1;
}
.伸展{
宽度:100%;
身高:100%;
}
这是一篇好文章

其要点是

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;
}

开尔文的答案是完美的,如果图像实际上比你想要放置它的空间大,并将其裁剪,设置宽度和高度将拉伸图像此固定图像:
背景大小:1024px 100%很高兴能够为您指出所需的方向:)我似乎无法使用
background
标记,但
background size:cover
似乎工作正常。