March 27, 2012

Is there a way to test for a scrollbar with just CSS?

Question by Jared

I want to know if the element is showing vertical scrollbars or not, and if it is possible to do this with CSS only.

This only needs to work for Firefox by the way.

Answer by BoltClock

If you mean using selectors to test, no, there isn’t such a selector in standard CSS (because the presence of scrollbars is calculated during rendering), nor can I find any selectors in this list of Mozilla vendor extensions that do what you’re looking for.

Answer by Starx

No, CSS cannot accomplish as this requires to be able to monitor the element, not apply styles.

Using jQuery

   var element = $("#yourdiv");
   if(element.get(0).scrollHeight > element.height()) {
       console.log('scroll bar is visible');
   }

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!