Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS @supports (::pseudo-element)

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.

like image 591
Martin Avatar asked Jan 25 '16 19:01

Martin


People also ask

How do you align pseudo elements?

You need to position the :before pseudo-element absolutely by using the well known centering technique (use the top, left, and transform properties). Here, -25px will offset the text above the circle. Note that for the <span> element, we set the position property to its "relative" value and the display to "block".

Can we create pseudo elements in inline CSS?

You can't specify inline styles for pseudo-elements. This is because pseudo-elements, like pseudo-classes (see my answer to this other question), are defined in CSS using selectors as abstractions of the document tree that can't be expressed in HTML.

What is pseudo e elements in CSS?

A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). For example, ::first-line can be used to change the font of the first line of a paragraph. /* The first line of every <p> element. */ p::first-line { color: blue; text-transform: uppercase; }

Is () CSS pseudo class?

The :is() CSS pseudo-class function takes a selector list as its argument, and selects any element that can be selected by one of the selectors in that list. This is useful for writing large selectors in a more compact form.


2 Answers

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%.

like image 176
CSSBurner Avatar answered Oct 19 '22 19:10

CSSBurner


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

like image 44
BoltClock Avatar answered Oct 19 '22 18:10

BoltClock