What are the methods to exceed the display scroll bar in css

coldplay.xixi
Release: 2023-01-05 16:12:27
Original
20802 people have browsed it

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].

What are the methods to exceed the display scroll bar in css

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

......
.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; }
Copy after login

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.

......
.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; }
Copy after login

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+
Copy after login
.element { -ms-overflow-style: none; }   Firefox
Copy after login
.element { overflow: -moz-scrollbars-none; }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!