0

How to hide the scrollbar without affecting the body width using JavaSCript? Whenever I click a button, the scrollbar gets hidden which is alright, but the body width gets affected. I want the body width remaining the same whether the scroll bar is hidden or not.

2
  • Please paste some code. Commented Nov 10, 2019 at 7:04
  • You can use css margin-right to do the UI trick. Need you to provide some example codes to work on the answer. Commented Nov 10, 2019 at 7:22

2 Answers 2

1

You can hide your scrollbar with the following styles without changing affecting on the body:

body::-webkit-scrollbar
  {
    width: 0;
  }

i hope this will work for you.

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

Comments

1

If you give the body overflow: hidden on clicking the button, you can set padding-right: 17px to the body.

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.