Css methods beyond displaying scroll bars: 1. Calculate the width of the scroll bar and hide it; 2. Surround it with three containers, without calculating the width of the scroll bar; 3. Customize the pseudo-object of the scroll bar Selector [::webkit-scrollbar].
The operating environment of this tutorial: windows7 system, css3 version, DELL G3 computer.
Css method for displaying scroll bars beyond:
Method 1: Calculate the width of the scroll bar and hide it
<div class="outer-container"> <div class="inner-container"> ...... </div> </div> .outer-container{ width: 360px; height: 200px; position: relative; overflow: hidden; } .inner-container{ position: absolute; left: 0; top: 0; right: -17px; bottom: 0; overflow-x: hidden; overflow-y: scroll; }
Comment: This code cleverly It has moved 17 pixels to the right, which is exactly equal to the width of the scroll bar. This value was obtained by manual debugging. No problem found in chrome and IE.
Method 2: Surrounded by three containers, no need to calculate the width of the scroll bar
This method adds an extra box compared to method 1, limiting the content to the box, so that You can scroll even if you can't see the scroll bar.
<div class="outer-container"> <div class="inner-container"> <div class="content"> ...... </div> </div> </div> .element, .outer-container { width: 200px; height: 200px; } .outer-container { border: 5px solid purple; position: relative; overflow: hidden; } .inner-container { position: absolute; left: 0; overflow-x: hidden; overflow-y: scroll; } .inner-container::-webkit-scrollbar { display: none; }
Method 3: Customize the pseudo-object selector of the scroll bar::webkit-scrollbar
This method is not compatible with IE and can be used for mobile applications.
.element::-webkit-scrollbar { width: 0 !important } IE 10+
.element { -ms-overflow-style: none; } Firefox
.element { overflow: -moz-scrollbars-none; }
Recommended related tutorials: CSS video tutorial
The above is the detailed content of What are the methods to exceed the display scroll bar in css. For more information, please follow other related articles on the PHP Chinese website!