Hiding the scroll bar on an HTML page

前端 未结 21 1096
旧巷少年郎
旧巷少年郎 2020-11-22 00:07

Can CSS be used to hide the scroll bar? How would you do this?

21条回答
  •  失恋的感觉
    2020-11-22 01:03

    Here's my solution, which theoretically covers all modern browsers:

    html {
        scrollbar-width: none; /* For Firefox */
        -ms-overflow-style: none; /* For Internet Explorer and Edge */
    }
    
    html::-webkit-scrollbar {
        width: 0px; /* For Chrome, Safari, and Opera */
    }
    

    html can be replaced with any element you want to hide the scrollbar of.

    Note: I've skimmed the other 19 answers to see if the code I'm posting has already been covered, and it seems like no single answer sums up the situation as it stands in 2019, although plenty of them go into excellent detail. Apologies if this has been said by someone else and I missed it.

提交回复
热议问题