.content {/* These rules create an artificially confined space, so we geta scrollbar that we can hide. They are not directly involved inhiding the scrollbar. */
border: 1px dashed gray;padding: .5em;
white-space: pre-wrap;height: 5em;overflow-y: scroll;}
.content {/* This is the magic bit for Firefox */scrollbar-width: none;}
.content::-webkit-scrollbar {/* This is the magic bit for WebKit */display: none;}
<div class='content'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris euurna et leo aliquet malesuada ut ac dolor. Fusce non arcu vel ligulafermentum sodales a quis sapien. Sed imperdiet justo sit amet venenatisegestas. Integer vitae tempor enim. In dapibus nisl sit amet purus conguetincidunt. Morbi tincidunt ut eros in rutrum. Sed quam erat, faucibusvel tempor et, elementum at tortor. Praesent ac libero at arcu eleifendmollis ut eget sapien. Duis placerat suscipit eros, eu tempor tellusfacilisis a. Vivamus vulputate enim felis, a euismod diam elementumnon. Duis efficitur ac elit non placerat. Integer porta viverra nunc,sed semper ipsum. Nam laoreet libero lacus.
Sed sit amet tincidunt felis. Sed imperdiet, nunc ut porta elementum,eros mi egestas nibh, facilisis rutrum sapien dolor quis justo. Quisquenec magna erat. Phasellus vehicula porttitor nulla et dictum. Sedtincidunt scelerisque finibus. Maecenas consequat massa aliquam pretiumvolutpat. Duis elementum magna vel velit elementum, ut scelerisqueodio faucibus.</div>
.hide-scroll {overflow: hidden;}
.viewport {overflow: auto;
/* Make sure the inner div is not larger than the container* so that we have room to scroll.*/max-height: 100%;
/* Pick an arbitrary margin/padding that should be bigger* than the max scrollbar width across the devices that* you are supporting.* padding = -margin*/margin-right: -100px;padding-right: 100px;}
body, html { /* These are defaults and can be replaced by hexadecimal color values */scrollbar-base-color: aqua;scrollbar-face-color: ThreeDFace;scrollbar-highlight-color: ThreeDHighlight;scrollbar-3dlight-color: ThreeDLightShadow;scrollbar-shadow-color: ThreeDDarkShadow;scrollbar-darkshadow-color: ThreeDDarkShadow;scrollbar-track-color: Scrollbar;scrollbar-arrow-color: ButtonText;}
从Internet Explorer 8开始,这些属性是以Microsoft为前缀的供应商,但它们仍然没有得到W3C的批准。
::-webkit-scrollbar-track-piece:start { /* Select the top half (or left half) or scrollbar track individually */ }::-webkit-scrollbar-thumb:window-inactive { /* Select the thumb when the browser window isn't in focus */ }::-webkit-scrollbar-button:horizontal:decrement:hover { /* Select the down or left scroll button when it's being hovered by the mouse */ }
%size {// set width and height}
.outer {// mask scrollbars of childoverflow: hidden;// set mask size@extend %size;// has absolutely positioned childposition: relative;}
.middle {// always have scrollbars.// don't use auto, it leaves vertical scrollbar showingoverflow: scroll;// without absolute, the vertical scrollbar showsposition: absolute;}// prevent text selection from revealing scrollbar, which it only does on// some webkit based browsers..middle::-webkit-scrollbar {display: none;}
.content {// push scrollbars behind mask@extend %size;}
/* Make parent invisible */#parent {visibility: hidden;overflow: scroll;}
/* Safari and Chrome specific style. Don't need to make parent invisible, because we can style WebKit scrollbars */#parent:not(*:root) {visibility: visible;}
/* Make Safari and Chrome scrollbar invisible */#parent::-webkit-scrollbar {visibility: hidden;}
/* Make the child visible */#child {visibility: visible;}
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 */}
<!DOCTYPE html><html lang="en"><meta charset="UTF-8"><title>Page Title</title>
<style>html, body {margin: 0;padding: 0}.content {scrollbar-width: none;}
.content::-webkit-scrollbar {display: none;}
.content {height: 100vh;overflow: scroll;}</style>
<body><div class="content"><h1>This is a Heading</h1><p>This is a paragraph.</p><p>This is another paragraph.</p><h1>This is a Heading</h1><p>This is a paragraph.</p><p>This is another paragraph.</p><h1>This is a Heading</h1><p>This is a paragraph.</p><p>This is another paragraph.</p><h1>This is a Heading</h1><p>This is a paragraph.</p><p>This is another paragraph.</p><h1>This is a Heading</h1><p>This is a paragraph.</p><p>This is another paragraph.</p><h1>This is a Heading</h1><p>This is a paragraph.</p><p>This is another paragraph.</p></div></body></html>