首页 > 解决方案 > 静态图像背景和滚动内容 css

问题描述

我想创建一个网页,在整个滚动过程中,背景需要说同样的话。因此,网页的真实内容就像漂浮在背景上一样。

抱歉,我没有任何例子,但这就像苹果有时在展示他们的 iPhone 芯片时所做的那样:有一段时间,页面保持相同的电子电路背景,但芯片规格(如速度)不断出现和滚动

标签: htmlcsscss-backgrounds

解决方案


您可以简单地使用:

body {
    background-image: url("...");
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed; /* This is what makes the background seem to be staying in the same position */
 }

但是,如果背景很大,可能会导致滚动效果变慢。


推荐阅读