使用 css 在滚动期间保持背景图像固定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2662039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Keep background image fixed during scroll using css
提问by X10nD
How do I keep the background image fixed during a page scroll? I have this CSS code, and the image is a background of the body and not <div></div>
如何在页面滚动期间保持背景图像固定?我有这个 CSS 代码,图像是身体的背景而不是<div></div>
body {
background-position:center;
background-image:url(../images/images5.jpg);
}
回答by Quentin
background-attachment: fixed;
http://www.w3.org/TR/CSS21/colors.html#background-properties
http://www.w3.org/TR/CSS21/colors.html#background-properties
回答by Chris Walter
background-image: url("/your-dir/your_image.jpg");
min-height: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: cover;}
回答by Omar Masry
Just add background-attachment to your code
只需将背景附件添加到您的代码中
body {
background-position: center;
background-image: url(../images/images5.jpg);
background-attachment: fixed;
}