Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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/3/gwt/3.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 - Fatal编程技术网

Css 如何在可能的右滚动条旁边浮动元素?

Css 如何在可能的右滚动条旁边浮动元素?,css,Css,我希望我的页面元素保持在相同的位置,不管右边缘是否有滚动条。我通过给主体100vw和给主体内容一个滚动条宽度的margin right实现了这一点。(为了简单起见,假设滚动条的宽度固定为16px。)但我不知道如何使右侧的内容粘贴到滚动条左边缘的位置 在下面的示例中,当滚动条出现时,“右”文本不应改变位置,其所有文本应保持可见,而无需硬编码其左(因为每次内容宽度改变时都必须改变) const{style}=main; 设置间隔(()=>{ //模拟大量的主要内容 style.height=sty

我希望我的页面元素保持在相同的位置,不管右边缘是否有滚动条。我通过给主体
100vw
和给主体内容一个滚动条宽度的
margin right
实现了这一点。(为了简单起见,假设滚动条的宽度固定为16px。)但我不知道如何使右侧的内容粘贴到滚动条左边缘的位置

在下面的示例中,当滚动条出现时,“右”文本不应改变位置,其所有文本应保持可见,而无需硬编码其
(因为每次内容宽度改变时都必须改变)

const{style}=main;
设置间隔(()=>{
//模拟大量的主要内容
style.height=style.height?“”:“1000px”;
}, 2000);
正文{
页边距顶部:40px;/*因为“结果”妨碍了*/
宽度:100vw;
保证金:0;
}
#对{
位置:绝对位置;
右:0;
}
#右>div{
右边距:16px;/*滚动条宽度*/
}
#主要{
填充顶部:60px;
右边距:16px;/*滚动条宽度*/
}
#主>分区{
文本对齐:居中;
保证金:0;
}

赖特
主要内容(不改变位置)

将左而非右与
vw
装置一起使用,并通过翻译进行校正:

const{style}=main;
设置间隔(()=>{
//模拟大量的主要内容
style.height=style.height?“”:“1000px”;
}, 2000);
正文{
页边距顶部:40px;/*因为“结果”妨碍了*/
宽度:100vw;
保证金:0;
}
#对{
位置:绝对位置;
左:100vw;/*一直向左*/
transform:translateX(计算(-1*(100%+16px));/*考虑到其宽度和滚动条宽度的100%向后移动*/
}
#右>div{
右边距:16px;/*滚动条宽度*/
}
#主要{
填充顶部:60px;
右边距:16px;/*滚动条宽度*/
}
#主>分区{
文本对齐:居中;
保证金:0;
}

赖特
主要内容(不改变位置)

很有趣。必须指定
left
,然后变换以将其移回,这似乎有点奇怪,但它可以工作,我很感激。@Snow这似乎是避免滚动效果的唯一方法。你需要考虑左参考而非右参考。