Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.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
Html 我想同时使用绝对位置和粘性位置。可能吗?如果是,那怎么办?_Html_Css - Fatal编程技术网

Html 我想同时使用绝对位置和粘性位置。可能吗?如果是,那怎么办?

Html 我想同时使用绝对位置和粘性位置。可能吗?如果是,那怎么办?,html,css,Html,Css,我希望能够将显示器和屏幕上的一个元素固定在同一位置,但不希望使用position:fixed,因为它会给其他元素带来问题。我希望元素高于其他元素,所以我使用了z-index。此外,我希望元素能够从一侧移动到另一侧,但不能在显示器上滚动。以下是我正在使用的代码: 如果元素是真正独立的,并且在层次上高于其他元素,我会将div移出其他嵌套div。此外,通过移动它,它将不再是应用了position:relative的父元素的子元素。这可能就是您在定位时遇到的问题 顺便说一下,通过使用fixed vs

我希望能够将显示器和屏幕上的一个元素固定在同一位置,但不希望使用position:fixed,因为它会给其他元素带来问题。我希望元素高于其他元素,所以我使用了z-index。此外,我希望元素能够从一侧移动到另一侧,但不能在显示器上滚动。以下是我正在使用的代码:




如果元素是真正独立的,并且在层次上高于其他元素,我会将div移出其他嵌套div。此外,通过移动它,它将不再是应用了position:relative的父元素的子元素。这可能就是您在定位时遇到的问题


顺便说一下,通过使用fixed vs sticky,您将获得更深入的浏览器支持

是的,我们可以通过设置高度来使用固定到父级的位置进行更新。以及使用calc css属性的子对象。我们能够做到这一点。这是下面的链接

演示:

家长

.position {     position: fixed;    height: 100%;}
儿童

.position .row {position: absolute;    left: calc(100% - 60%);    top: calc(100% - 60%);}

您可以通过以下方式实现此目的:

家长:

position: absolute;
...
position: sticky;
top: 0;
height: 100vh;
子项:

position: absolute;
...
position: sticky;
top: 0;
height: 100vh;
注意1:确保父元素(DOM树上)没有
溢出:隐藏
。如果是,请将其更改为
溢出:可见


注意2:确保子元素具有固定高度(而不是%)

您好,
display:fixed
到底导致了什么问题?也许我们可以解决这个问题?附加的图像在哪里?我看不到。在第一个元素上尝试
width:100vw
,我刚刚添加了图像。我第一次忘了这么做。你可以将元素设置为
display:fixed
,只需
margin:auto
或flex来对齐你的身体可能这是在不同的线程中提出的相同问题