html - How to offset for scrollbar width with css?
问题描述
I had to set these properties and make my scrollbar appear on top of the page because it was making my lightbox jitter when I clicked on an image.
html {
overflow-y: scroll;
overflow-y: overlay;
}
However on mobile this makes it seem like I have no margin on the right as it appears behind the scrollbar.
Is there a way that I can offset my content on the right to match the scrollbars width, while still keeping it on top of everything?
The container the images are inside has 4% margin on the left and right but the scrollbar is displaying over it on the right.
解决方案
我想出了一个不涉及知道滚动条宽度的问题的解决方案。
首先,这个问题的表述很糟糕,原因有两个:
- 在移动设备上,滚动条与大屏幕上的滚动条不同,因此不会妨碍您
- 它确实干扰了我的灯箱插件(fancybox),但解决方案要简单得多
如果有人因为类似的问题来到这里,解决方案是申请
overflow-y: scroll;
overflow-y: overlay;
到<body>
标签,而不是html
作为灯箱插件可以在您单击图像后以这种方式覆盖它。
推荐阅读
- python - Using a 'for ... else' statement to return the loop variable
- php - Is this a good practice to connect to a database connection file outside rood dir?
- javascript - gradlew app:assembleRelease Error in react-native
- react-native - How can I use PureComponent when I don't use Classes?
- reactjs - 类型“字符串”(TypeScript)上不存在属性“strDrink”
- python - 我无法专门为 python2 安装包,pip 和 pip3 指向相同的版本
- python - Make this usage method with argparse
- json - How can I format a DateTime instance to Json
- python-3.x - botocore and urllib3 conflicting dependencies
- r - How to use stringr functions to remove all empty words?