Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide scroll bar, but while still being able to scroll

I want to be able to scroll through the whole page, but without the scrollbar being shown.

In Google Chrome it's:

::-webkit-scrollbar {     display: none; } 

But Mozilla Firefox and Internet Explorer don't seem to work like that.

I also tried this in CSS:

overflow: hidden; 

That does hide the scrollbar, but I can't scroll any more.

Is there a way I can remove the scrollbar while still being able to scroll the whole page?

With just CSS or HTML, please.

like image 930
Oussama el Bachiri Avatar asked May 21 '13 13:05

Oussama el Bachiri


People also ask

How can I hide scrollbar in iframe but still scroll?

1. Set the overflow of the parent div as hidden. 2. Set the overflow of the child div to auto and the width 200% (or anything more than 100%, or more than the width of the parent - so that the scrollbar gets hidden).


1 Answers

Just a test which is working fine.

#parent{     width: 100%;     height: 100%;     overflow: hidden; }  #child{     width: 100%;     height: 100%;     overflow-y: scroll;     padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */     box-sizing: content-box; /* So the width will be 100% + 17px */ } 

Working Fiddle

JavaScript:

Since the scrollbar width differs in different browsers, it is better to handle it with JavaScript. If you do Element.offsetWidth - Element.clientWidth, the exact scrollbar width will show up.

JavaScript Working Fiddle

Or

Using Position: absolute,

#parent{     width: 100%;     height: 100%;     overflow: hidden;     position: relative; }  #child{     position: absolute;     top: 0;     bottom: 0;     left: 0;     right: -17px; /* Increase/Decrease this value for cross-browser compatibility */     overflow-y: scroll; } 

Working Fiddle

JavaScript Working Fiddle

Information:

Based on this answer, I created a simple scroll plugin.

like image 178
Mr_Green Avatar answered Oct 21 '22 14:10

Mr_Green