[英]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.图像所在的容器在左侧和右侧有 4% 的边距,但滚动条显示在右侧。
I figured out a solution to my problem that did not involve knowing the width of the scroll bar.我想出了一个不涉及知道滚动条宽度的问题的解决方案。
First of all the question was poorly formulated for 2 reasons:首先,这个问题的表述很糟糕,原因有两个:
If anyone comes here because of a similar issue, the solution was to apply如果有人因为类似的问题来到这里,解决方案是申请
overflow-y: scroll;
overflow-y: overlay;
to the <body>
tag instead of html
as the lightbox plugin could overwrite it that way once you click on an image.到
<body>
标签而不是html
,因为一旦您单击图像,灯箱插件可能会以这种方式覆盖它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.