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.

1
  • 1
    I think you will need modernizr.com Commented Jan 25, 2016 at 19:44

4 Answers 4

14

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 February 2024, browser support for @supports selector is roughly 94%.

Sign up to request clarification or add additional context in comments.

1 Comment

There are many (mostly outdated) suggestions in this answer, but as of 2021-09, @supports selector(::-webkit-scrollbar-thumb){/*Chrome yay, Firefox nay*/} does work if it must.
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.)

1 Comment

Outdated now, see most upvoted answer.
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.

Comments

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)`)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.