全屏背景图像,最大宽度

Ben*_*ter 2 css css3

我正在使用这里描述的第一种技术创建一个"全屏"背景图像,可以与浏览器成比例地缩放.

我的图像容器的CSS是:

.fs-img {
    position: fixed;
    top: 4.5em;
    right: 0;
    bottom: 0;
    left: 0;
    background: url('image.jpg') no-repeat center center fixed; 
    background-size: cover;
}
Run Code Online (Sandbox Code Playgroud)

但是我想max-width在我的网站上设置1200px.当然,将其应用于身体元素对图像没有影响position: fixed.

那么是否有另一种方法可以使全屏图像具有最大宽度,同时仍保持固定在底部?

这是我正在测试的演示网站.

Pet*_*ete 5

我认为您可以使用以下样式实现您想要的效果:

.fs-img {
    position: fixed;
    top: 4.5em;
    right: 50%;
    bottom: 0;
    left: 50%;
    margin:0 -600px;
    background: url(image.jpg) no-repeat center center; 
    background-size: cover;
}
Run Code Online (Sandbox Code Playgroud)