CSS @supports (::伪元素)

标签 css css-selectors pseudo-element

我想将一个区域更改为最大溢出:仅当支持 ::-webkit-scrollbar-thumb 时才滚动。

在纯 CSS 中这有可能吗?看起来 @supports 只检查规则,没有选择器。

最佳答案

您现在可以使用 @supports selector()以伪元素为目标。以下是您的用例的相关示例:

@supports selector(::-webkit-scrollbar-thumb) {

    .scroll-container {
        overflow: scroll
    }

}

请参阅this JSFiddle ,它演示了浏览器对 ::-webkit-scrollbar-thumb 的支持

  1. Chrome 86
  2. 边缘 87
  3. 歌剧 72

但不是

  1. 火狐 82
  2. Safari 12

截至 2020 年 12 月,browser support @supports selector 大约为 72%。

关于CSS @supports (::伪元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35000865/

相关文章:

css - 以垂直和水平行居中 Bootstrap 面板

html - 固定导航栏在添加滤镜模糊时消失

html - img 高度不起作用

CSS 相邻选择器问题

css - 根据子元素的匹配设置不同的背景图像

javascript - 为什么动画不透明度在 chrome 中不起作用?

html - 第一个子元素的CSS选择器

css - 多个伪元素

html - 伪元素 :after changes size of parent div component

css - 获取:before pseudo element to use background image of parent