我们可以删除 CSS 属性“-webkit-scrollbar”吗?来自单个节点?
如何从单个 HTML 元素中删除 CSS 属性 ::-webkit-scrollbar
?
在我的 CSS 文件中,我有这样的代码:
::-webkit-scrollbar {
width: 6px;
height: 6px;
background-color:transparent;
}
::-webkit-scrollbar-track {
background-color:transparent;
width: 6px;
}
::-webkit-scrollbar-track-piece {
background-color: blue;
}
::-webkit-scrollbar-thumb {
background-color: #d4dee8;
width: 6px;
}
它将用 webkit 滚动条替换每个滚动条。但是有两个地方我不需要 webkit 滚动条,我需要普通的滚动条。
HTML 文件:
<td class="viewDialogLabel" height="21" style="width:156px;padding:0px">
<!-- Inner elements --->
</td>
在这里,我需要将类 viewDialogLabel
更改为普通滚动条。
我怎样才能得到这个效果?
How can I drop the CSS property ::-webkit-scrollbar
from a single HTML element?
In my CSS file, I have this code:
::-webkit-scrollbar {
width: 6px;
height: 6px;
background-color:transparent;
}
::-webkit-scrollbar-track {
background-color:transparent;
width: 6px;
}
::-webkit-scrollbar-track-piece {
background-color: blue;
}
::-webkit-scrollbar-thumb {
background-color: #d4dee8;
width: 6px;
}
It will replace every scrollbar with webkit scrollbars. But there are two places where I don't need webkit scrollbar, I need normal scrollbars instead.
HTML file:
<td class="viewDialogLabel" height="21" style="width:156px;padding:0px">
<!-- Inner elements --->
</td>
Here, I need to change class viewDialogLabel
to normal scrollbars.
How do I get this effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
WebKit 支持方便的 CSS 值
initial
,它将属性设置回如果没有样式应用于页面,它们将具有的值。因此,您可以像这样重置
::-webkit-scrollbar
值:请参阅 http://jsfiddle.net/uVGKr/
WebKit 还支持
:not()
选择器,所以我认为对原始 CSS 的以下修改会阻止自定义滚动条应用于该表格单元格:但是,它对我不起作用在 Chrome 16 中 - 根本不应用自定义滚动条样式(请参阅 http://jsfiddle.net/uVGKr/ 1/)。我不确定我是否做错了什么,是否无法组合这些选择器,或者这是否是一个 WebKit 错误。
根据您建议的编辑,从 CSS 中删除
td
选择器,这似乎至少在 Chrome 24 中有效:http://jsfiddle.net/uVGKr/2/WebKit supports the handy CSS value
initial
, which sets properties back to the values they would have had if no styles applied to the page.So, you can reset the
::-webkit-scrollbar
values you’ve set like this:See http://jsfiddle.net/uVGKr/
WebKit also supports the
:not()
selector, so I would have thought the following amendment to your original CSS would prevent the custom scrollbars from applying to that table cell:However, it doesn’t work for me in Chrome 16 — the custom scrollbar styles aren’t applied at all (see http://jsfiddle.net/uVGKr/1/). I’m not sure if I’m doing something wrong, if you just can’t combine these selectors, or if this is a WebKit bug.
As per your suggested edit removing the
td
selectors from the CSS, this seems to be working in Chrome 24 at least: http://jsfiddle.net/uVGKr/2/您可以指定更准确的选择器:
然后,只有具有 new-scrollbar 类的元素才会具有自定义滚动条。
或者您可以尝试覆盖特定元素中的属性:
也可以尝试使用不同的属性/值。
You can specify a more accurate selector:
Then, only elements with the class new-scrollbar will have the custom scrollbars.
Or you can try to override the properties in specific elements:
Also try it with different properties / values.
您可以为这两个元素指定单独的类或 id,并用新的样式覆盖 -webkit-scrollbar 样式,而不是从这两个元素中删除这些属性
Instead of removing these properties from those two elements you can specify a separate class or ids for these two elements and override the -webkit-scrollbar styles with new ones