html - 将::-webkit-scrollbar 应用于一个特定元素

标签 html css

我使用 ::-webkit-scrollbar 来解决当用户在 Android 设备上快速滚动条款和条件时出现的问题。元素的其余大部分使用 iScroll .我只想将 ::-webkit-scrollbar 属性应用于条款和条件 div,而不是其他任何地方,因为 iScroll 用于其他任何地方。 html 是:

<section class="content">
<h1>
    <strong>Terms & conditions</strong>
</h1>

<p>blah blah</p>
....
</section>

我以为我可以用 CSS 做到这一点:

.content ::-webkit-scrollbar {
    width: 5px; 
}

.content ::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.5);
}

.content ::-webkit-scrollbar-thumb {
    margin-right: 5px;
    border-radius: 5px;
    background: rgba(255,255,255,0.5);
}

但是通过使用 .content 前缀,webkit-scroller 不被应用并且没有滚动条被应用。如果我省略 .content,它会起作用,但随后也会应用于我不想要的其他区域。关于如何使用 ::-webkit-scrollbar 只定位一个特定元素有什么想法吗?

最佳答案

去掉.content::-webkit之间的空格:

.content::-webkit-scrollbar {
    width: 5px; 
}

在那里留下空间意味着您正在寻找 .contentchildren 而不是容器本身。

jsFiddle

关于html - 将::-webkit-scrollbar 应用于一个特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25402874/

相关文章:

jquery - 改变li的位置

javascript - 如何对 Playground 中闪电网络组件 "datatable"的 tds 应用一些简单的样式?

html - 如何在嵌套的 div 内将 span 标签 float 到表外而不被截断?

html - 从 GitHub Pages 上托管的静态页面发送电子邮件

android - 如何在android中以html格式的电子邮件发送图像?

javascript - 如何在 React 日期范围选择器中获取开始和结束日期值?

html - compass 中的垂直节奏和边距调整

jquery - wcf 服务被调用两次

html - CSS "background-position: bottom"在移动浏览器上不完美

javascript - 100% 高度不适用于浏览器调整大小