10

On a page I am having a webkit scrollbar which has been hidden using display: none css property.

#element::-webkit-scrollbar {
    display: none;
}

In one of my app level css files I tried to override the above css rule, but I wasn't able to display the scrollbar

I tried changing the css but I couldn't the get exact scrollbar which would have been there if display: none property was not present.

#element::-webkit-scrollbar {
    -webkit-appearance: none;
     width: 7px;
     display: block;
}

#element::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background-color: rgba(0,0,0,.5);
    -webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);
}

The above css made the scroll bar visible but it gave me ugly scroll bar (probably due the css rules I have used).

Is there a simple way in which I can display the webkit scrollbar which would been there if the display:none property was not present. I can not change the display:none as it is being inherited by my app. I can only over-ride that rule.

EDIT:

An exactly similar question was asked How to override "::-webkit-scrollbar" CSS rule and make scrollbar visible again, but it seems that also doesn't have an accepted answer.

7
  • 1
    Use a class like allow-scroll, then select with #element:not(.allow-scroll)::-webkit-scrollbar for your display: none. Then just add/remove the class with JavaScript. Commented Sep 5, 2014 at 12:08
  • Unfortunately ::-webkit-scrollbar only supports in Chrome Browser ! Commented Sep 5, 2014 at 12:08
  • @AtalShrivastava: I am facing this problem on chrome only. Commented Sep 5, 2014 at 12:10
  • @DJDavid98: I didn't exactly get what you meant by "then select with #element:not(.allow-scroll)::-webkit-scrollbar for your display: none". Can it be done by css alone? Commented Sep 5, 2014 at 12:13
  • Webkit Vertical Scrollbar This could help you on better understanding on webkit scrollbar Commented Sep 5, 2014 at 12:15

4 Answers 4

1

you can do something like this

*:not(.excluded-element)::-webkit-scrollbar { display: none; }

reads as: apply it to everything except the .excluded-element

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

Comments

0

Not a full solution, but somewhat working approach is proposed in this SuperUser answer: https://superuser.com/a/1685163/814616

The catch is in reverting not only display property, but all scrollbar related rules. That resets all colors, though, so they need to be redefined.

Comments

-1

If the display:none is what it's hiding it why don't you just overwrite the display instead of adding that other properties?

Try overwriting the display with the different values it can has:

https://developer.mozilla.org/en-US/docs/Web/CSS/display

1 Comment

I tried all the options display property can have, but none seem to work.
-1

Edit: Does not seem to work, as pointed out in the comments.

I was able to restore the scrollbars using

#element::-webkit-scrollbar {
    display: unset;
}

1 Comment

Not even this works. I've tried every possible value but it seems if you have set display:none it is non-reversible. Same conclusion as @TheRock

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.