gpt4 book ai didi

css - 无法使用 css 获取背景图像以随内容滚动(背景附件 : scroll)

转载 作者:行者123 更新时间:2023-11-28 10:56:51 25 4
gpt4 key购买 nike

我正在尝试使 div 中的背景图像可滚动(不固定)。

我试过复制示例 2:(通常有效...例如 IE9)

http://www.codertools.com/css_help_guide/css_background-attachment.aspx

这是我的版本:(有时不起作用)

http://sky-walker.net/temp/panning/panning2.html

我基本上已经复制并粘贴了代码(图像文件的路径除外),但是如果我滚动 div,背景图像将保持固定...

我想让背景图像滚动,就像示例 2 中那样。

我的问题发生在 IE9 (Windows 7) 和 Chrome 12(Windows 7 和 Windows XP)中,但 IE6 (Windows XP) 没有。在 Chrome 12 for Vista 中,第一个链接(示例 2)也不起作用。

最佳答案

为什么背景图片要滚动?你的两个例子对我来说都一样。

CSS2 specs :

If an element has a scrolling mechanism (see 'overflow'), a 'fixed' background does not move with the element, and a 'scroll' background does not move with the scrolling mechanism.

CSS3 specs :

scroll
The background is fixed with regard to the element itself and does not scroll with its contents. (It is effectively attached to the element's border.)

虽然背景确实随视口(viewport)滚动


编辑:我认为您真正想要的是 CSS3 的 local background-attachment:

local
The background is fixed with regard to the element's contents: if the element has a scrolling mechanism, the background scrolls with the element's contents.

关于css - 无法使用 css 获取背景图像以随内容滚动(背景附件 : scroll),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6887731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com