CSS滚动条样式跨浏览器
如何定义跨浏览器的 CSS 滚动条样式?我测试了这段代码,它只在 IE 和 Opera 中有效,但在 Chrome、Safari 和 Firefox 中失败。
<style type="text/css">
<!--
body {
scrollbar-face-color: #000000;
scrollbar-shadow-color: #2D2C4D;
scrollbar-highlight-color:#7D7E94;
scrollbar-3dlight-color: #7D7E94;
scrollbar-darkshadow-color: #2D2C4D;
scrollbar-track-color: #7D7E94;
scrollbar-arrow-color: #C1C1D1;
}
-->
</style>
How can I define a CSS scrollbar style cross browser? I tested this code, it only works in IE and opera, but failed in Chrome, Safari and Firefox.
<style type="text/css">
<!--
body {
scrollbar-face-color: #000000;
scrollbar-shadow-color: #2D2C4D;
scrollbar-highlight-color:#7D7E94;
scrollbar-3dlight-color: #7D7E94;
scrollbar-darkshadow-color: #2D2C4D;
scrollbar-track-color: #7D7E94;
scrollbar-arrow-color: #C1C1D1;
}
-->
</style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Webkit 对滚动条的支持相当复杂。这个CSS提供了一个非常小的滚动条,带有浅灰色轨道和深色拇指:
这个答案是额外的绝佳来源信息。
Webkit's support for scrollbars is quite sophisticated. This CSS gives a very minimal scrollbar, with a light grey track and a darker thumb:
This answer is a fantastic source of additional information.
滚动条 CSS 样式是 Microsoft 开发人员发明的一个奇怪的东西。它们不是 W3C CSS 标准的一部分,因此大多数浏览器都会忽略它们。
Scrollbar CSS styles are an oddity invented by Microsoft developers. They are not part of the W3C standard for CSS and therefore most browsers just ignore them.
jScrollPane 是跨浏览器滚动条的一个很好的解决方案,并且可以很好地降级。
jScrollPane is a good solution to cross browser scrollbars and degrades nicely.
nanoScrollerJS 使用起来很简单。我总是使用它们...
文档中的代码示例,
nanoScrollerJS is simply to use. I always use them...
Code example from the Documentation,
从 IE6 开始,我相信您无法使用这些属性自定义滚动条。上面链接的 Chris Coyier 文章详细介绍了用于自定义滚动条的 webkit 专有 CSS 选项。
如果你真的想要一个可以完全自定义的跨浏览器解决方案,你将不得不使用一些 JS。这里有一个名为 FaceScroll 的不错插件的链接:http://www.dynamicdrive。 com/dynamicindex11/facescroll/index.htm
As of IE6 I believe you cannot customize the scroll bar using those properties. The Chris Coyier article linked to above goes into nice detail about the options for webkit proprietary css for customizing the scroll bar.
If you really want a cross browser solution that you can fully customize you're going to have to use some JS. Here is a link to a nice plugin for it called FaceScroll: http://www.dynamicdrive.com/dynamicindex11/facescroll/index.htm
尝试一下,它非常容易使用,并在 IE、Safari 和 FF 上进行了测试,并且工作正常,而且不需要太多
div
,只需添加id
即可正常工作,链接 Js 和 Css 文件后。 FaceScroll自定义滚动条希望它能帮助
编辑
步骤 1:将以下脚本添加到页面的部分:
步骤 2:然后在页面的正文中,将以下示例 HTML 块添加到页面。
try this it's very easy to use and tested on IE and Safari and FF and worked fine and beside no need for many
div
around it just addid
and it will work fine, after you link you Js and Css files. FaceScroll Custom scrollbarhope it help's
Edit
Step 1: Add the below script to the section of your page:
Step 2: Then in the BODY of your page, add the below sample HTML block to your page.