CSS - 溢出:滚动; - 总是显示垂直滚动条?
所以目前我有:
#div {
position: relative;
height: 510px;
overflow-y: scroll;
}
但是我不相信对于某些用户来说,那里有更多内容是显而易见的。他们可以向下滚动页面,而不知道我的 div 实际上包含更多内容。我使用高度 510px,这样它会截掉一些文本,因此在某些页面上看起来确实有更多内容,但这并不适用于所有页面。
我使用的是 Mac,在 Chrome 和 Safari 中,只有当鼠标位于 Div 上并且您主动滚动时才会显示垂直滚动条。有没有办法让它一直显示?
So currently I have:
#div {
position: relative;
height: 510px;
overflow-y: scroll;
}
However I don't believe that it will be obvious to some users that there is more content there. They could scroll down the page without knowing that my div actually contains a lot more content. I use the height 510px so that it cuts off some text so on some pages it does look like that there is more content, but this doesn't work for all of them.
I am using a Mac, and in Chrome and Safari the vertical scroll bar will only show when the mouse is over the Div and you actively scroll. Is there a way to always have it displaying?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我自己刚刚遇到这个问题。 OSx Lion 在不使用时隐藏滚动条,使其看起来更“光滑”,但同时出现了您解决的问题:人们有时无法看到 div 是否具有滚动功能。
修复:在你的CSS中包含 -
根据需要自定义外观。 来源
Just ran into this problem myself. OSx Lion hides scrollbars while not in use to make it seem more "slick", but at the same time the issue you addressed comes up: people sometimes cannot see whether a div has a scroll feature or not.
The fix: In your css include -
customize the apperance as needed. Source
对于 2021 年及以后来到这里的任何人:
“iOS 14 不再支持自定义滚动条。”< /a>
根据developer.apple.com 论坛上的官方“框架工程师”的说法。
For anyone coming here in 2021 and later years:
"Custom scrollbars are no longer supported in iOS 14."
according to an official "Frameworks Engineer" on the developer.apple.com forums.
请注意,在 iPad Safari 上,如果 CSS 中的某处有 -
webkit-overflow-scrolling: touch;
,NoviceCoding 的解决方案将不起作用。解决方案是删除所有出现的
-webkit-overflow-scrolling: touch;
或将-webkit-overflow-scrolling: auto;
与新手编码的解决方案。
Please note on iPad Safari, NoviceCoding's solution won't work if you have -
webkit-overflow-scrolling: touch;
somewhere in your CSS.The solution is either removing all the occurrences of
-webkit-overflow-scrolling: touch;
or putting-webkit-overflow-scrolling: auto;
withNoviceCoding's solution.
根据我的测试,这将在 iOS 7.1.x 上的 Safari 上与 iPad 配合使用,但我不确定是否适用于 iOS 6。但是,它不适用于 Firefox。有一个旨在跨浏览器兼容的 jQuery 插件,称为 jScrollPane。
另外,Stack Overflow 上有一个重复的帖子 其中还有一些其他细节。
This will work with iPad on Safari on iOS 7.1.x from my testing, I'm not sure about iOS 6 though. However, it will not work on Firefox. There is a jQuery plugin which aims to be cross browser compliant called jScrollPane.
Also, there is a duplicate post here on Stack Overflow which has some other details.
您只需按一定间隔来回抖动滚动条一个像素:) 已
在 Chrome 和 Firefox for macOS (14.4.1) 上测试并运行。
不适用于具有 One UI (6.1) 的 Android Chrome (14) 第一次交互后。
You could just jitter the scrollbar back and forth a pixel on an interval :)
Tested and works on Chrome and Firefox for macOS (14.4.1).
Doesn't work on Chrome for Android (14) with One UI (6.1) after the first interaction.