20

I want to change an area to max overflow:scroll only if ::-webkit-scrollbar-thumb is supported.

Is that possible somehow in pure CSS? As it seems @supportsonly checks rules, no selectors.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Martin
  • 2,007
  • 6
  • 28
  • 44

4 Answers4

9

You can now use @supports selector() to target pseudoelements. Here is a relevant example for your use case:

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

    .scroll-container {
        overflow: scroll
    }

}

Please see this JSFiddle, which demonstrates browser support for ::-webkit-scrollbar-thumb in

  1. Chrome 86
  2. Edge 87
  3. Opera 72

but not

  1. Firefox 82
  2. Safari 12

As of December 2020, browser support for @supports selector is roughly 72%.

CSSBurner
  • 1,565
  • 15
  • 13
  • There are many (mostly outdated) suggestions in [this answer](https://stackoverflow.com/a/25496712/2083613), but as of 2021-09, `@supports selector(::-webkit-scrollbar-thumb){/*Chrome yay, Firefox nay*/}` does work if it must. – dakab Sep 07 '21 at 08:21
4

You are correct. @supports only deals with property-value combinations. The only way you could do this in pure CSS is with a CSS hack targeting browsers that support ::-webkit-scrollbar-thumb. (Not enough browsers support @supports for it to be useful in checking support for ::-webkit-scrollbar-thumb anyway.)

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
0

Adding up to the previous answer, you can just write the pseudo selector, if a browser doesnt support the prop, it will skip the css declaration.

For example:

li::marker{color:blue}

won't be seen by older browsers.

0

This is what I used to identify Webkit browsers. It's the most specific pseudo selector I could find that no other engine seems to have (yet):

CSS.supports(`selector(input[type='time']::-webkit-calendar-picker-indicator)`)
jsaddwater
  • 1,781
  • 2
  • 18
  • 28