Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 元素在调整大小时随背景移动_Css_Html - Fatal编程技术网

Css 元素在调整大小时随背景移动

Css 元素在调整大小时随背景移动,css,html,Css,Html,我目前正在建立一个单页滚动网站 在第二页中,我使用了背景大小为:cover属性的背景。基本上,我希望一个元素位于背景之上,但在调整大小时与背景相对应地移动,即使这意味着元素移出视口 这可能吗 到目前为止,我所尝试的: .background { width:100%; height:100vh; margin:0; background-image: url('Studio.jpg'); background-repeat: no-repeat; background-size: cover

我目前正在建立一个单页滚动网站

在第二页中,我使用了背景大小为:cover属性的背景。基本上,我希望一个元素位于背景之上,但在调整大小时与背景相对应地移动,即使这意味着元素移出视口

这可能吗

到目前为止,我所尝试的:

.background {
width:100%; 
height:100vh; 
margin:0;
background-image: url('Studio.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: 80% 0%;
overflow: hidden;
position: relative;
z-index: 1;
}

#image {
height: 100%;
width:100%;
background-image: url('lamp.png');
background-repeat: no-repeat;
background-size: auto;
position: absolute;
}
我制作了一张图表,以更好地解释我试图实现的目标:

第一个图表显示了布局在全尺寸视口中的外观。 第二个图表显示了调整视口大小时我希望布局的外观。。。因此,图像元素相对于背景移动,离开视图端口


听起来像视差滚动或位置:固定在元素上。

这可能吗?可能吧,但是如果没有看到代码,我们就不知道你在说什么。向我们展示您的尝试。向问题添加了代码。位置:修复了不允许元素相对于背景移动的问题。