24

I want to target elements which have a visible scrollbar using only CSS. Is this possible without javascript?

For example, If I have 3 divs styled with overflow-y:auto, How do I change the styles for them only when their scrollbar has appeared?

cronoklee
  • 5,957
  • 8
  • 47
  • 75
  • 8
    I don't think this is possible but I'd like to be proved wrong – Jonas Grumann Jun 29 '15 at 11:49
  • I think this is similar to question [link](http://stackoverflow.com/questions/16865167/is-there-a-css-selector-that-will-select-elements-with-overflowing-text), It does not seem possible using CSS only – KAD Jun 29 '15 at 11:50
  • 1
    Not with pure CSS. I know you said no JS, but this might be useful if you change your mind http://stackoverflow.com/questions/4814398/how-can-i-check-if-a-scrollbar-is-visible – Equalsk Jun 29 '15 at 14:12
  • I suppose it wouldn't be possible to style elements depending if there is a scrollbar or not. Consider the scenario where when you have a scrollbar you you alter the height of the elements inside so the scrollbar is removed, then they get to their original height, the scrollbar appears and so on... – xpy Jul 29 '16 at 08:36

1 Answers1

14

CSS does not cover this selection. You need to use JavaScript.

Teo Maragakis
  • 421
  • 4
  • 11