存在滚动条时绝对 div 移动 [英] Absolute div shifts when scrollbar is present
问题描述
我的页面的全部内容有问题.
问题是没有滚动条,我的内容向右大约 20 像素,但是当滚动条出现时,它会向左移动.我必须通过将它定位在内容上方 20 像素来补偿绝对定位的 div,直到出现滚动条,因为它位于页面的右侧.
i have a problem with the entire content of my page.
The problem being without a scrollbar present my content is about 20px to the right, but when a scrollbar is present it shifts to the left.
I have to compensate for this for an absolute postioned div by positioning it over the content by 20px until a scrollbar is present as it rests at the right hand side of the page.
代表我这是一个糟糕的错误,但我只是想要一个简单的方法来解决这个问题.有什么快速简便的建议吗?将主要内容 div 设为绝对内容会更好吗?
This is a crappy fault on my behalf but i just want an easy way to fix this. Any quick and easy suggestions? Would i be better off making the main content div an absolute one?
推荐答案
一种快速而肮脏的方法是始终强制滚动条可见:
One quick and dirty way is to always force the scrollbar to be visible with:
html { 溢出-y:滚动;}
不理想,但如果缺少滚动条偏移破坏了您的设计,它可以标准化外观.
Not ideal, but it standardizes the appearance if the lack of scrollbar offset is breaking your design.
这篇关于存在滚动条时绝对 div 移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!