Hide browser scroll-bars
When you ask the question, "Can the scroll-bars of a browser be removed in some way, rather than simply hidden or camouflaged", everyone will say "Not possible" because it is not possible to remove the scrollbars from all browsers in a compliant and cross-compatible way, and then there's the whole argument of usability.
However, it is possible to prevent the browser from ever having the need to generate and display scrollbars if you do not allow your webpage to overflow.
This just means that we have to proactively substitute the same behavior that the browser would typically do for us and tell the browser thanks but no thanks buddy.
Here's a simple example from the popular iScroll javascript plugin.
<!-- begin snippet: js hide: false -->
<!-- language: lang-js -->
/* original demo: https://github.com/cubiq/iscroll */
var myScroll;
function loaded () {
myScroll = new IScroll('#wrapper');
}
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
<!-- language: lang-css -->
body {
/* On modern browsers, prevent the whole page to bounce */
overflow: hidden;
}
#wrapper {
position: relative;
width: 300px;
height: 300px;
overflow: hidden;
/* Prevent native touch events on Windows */
-ms-touch-action: none;
/* Prevent the callout on tap-hold and text selection */
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
/* Prevent text resize on orientation change, useful for web-apps */
-webkit-text-size-adjust: none;
-moz-text-size-adjust: none;
-ms-text-size-adjust: none;
-o-text-size-adjust: none;
text-size-adjust: none;
}
#scroller {
position: absolute;
/* Prevent elements to be highlighted on tap */
-webkit-tap-highlight-color: rgba(0,0,0,0);
/* Put the scroller into the HW Compositing layer right from the start */
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
-o-transform: translateZ(0);
transform: translateZ(0);
}
<!-- language: lang-html -->
<body onload="loaded()">
<div id="wrapper">
<div id="scroller">
<p><strong>This demo relies on a dependency so you'll have to check out this link: https://github.com/cubiq/iscroll</strong></p>
</div>
</div>
<!-- end snippet -->
Now as I mentioned.. all the vendor specific ways of manipulating scroll-bars for the same of being thorough..
Internet Explorer 5.5+
*These properties were never part of the CSS spec, nor were they ever approved or vendor prefixed but they work in Internet Explorer and Konqueror.
body, html { /* these are default, can be replaced by hex color values */
scrollbar-face-color: ThreeDFace;
scrollbar-shadow-color: ThreeDDarkShadow;
scrollbar-highlight-color: ThreeDHighlight;
scrollbar-3dlight-color: ThreeDLightShadow;
scrollbar-darkshadow-color: ThreeDDarkShadow;
scrollbar-track-color: Scrollbar;
scrollbar-arrow-color: ButtonText;
}
Some of these properties were properly vendor-prefixed with the release of IE9 but they are merely pseudonyms for the pre-existing non-prefixed properties. These are:
-ms-scrollbar-3dlight-color
, -ms-scrollbar-darkshadow-color
, -ms-scrollbar-shadow-color
Further details about Internet Explorer
IE makes scroll
available which sets whether or not to disable or enable scroll bars or gets the value of the position of the scroll bars.
With Microsoft Internet Explorer 6 and later, when you use the !DOCTYPE declaration to specify standards-compliant mode, this attribute applies to the HTML element. When standards-compliant mode is not specified, as with earlier versions of Windows Internet Explorer, this attribute applies to the BODY element, not the HTML element.
It's also worth noting that when working with .NET the ScrollBar class in System.Windows.Controls.Primitives
in the Presentation framework is responsible for rendering the scrollbars.
http://msdn.microsoft.com/en-us/library/ie/ms534393(v=vs.85).aspx
Webkit
Webkit extensions related to scroll-bar customization are:
::-webkit-scrollbar {} /* 1 */
::-webkit-scrollbar-button {} /* 2 */
::-webkit-scrollbar-track {} /* 3 */
::-webkit-scrollbar-track-piece {} /* 4 */
::-webkit-scrollbar-thumb {} /* 5 */
::-webkit-scrollbar-corner {} /* 6 */
::-webkit-resizer {} /* 7 */
These can each be combined with additional pseudo selectors (expand list below):
-
:horizontal
– The horizontal pseudo-class applies to any scrollbar pieces that have a horizontal orientation. -
:vertical
– The vertical pseudo-class applies to any scrollbar pieces that have a vertical orientation. -
:decrement
– The decrement pseudo-class applies to buttons and track pieces. It indicates whether or not the button or track piece will decrement the view’s position when used (e.g., up on a vertical scrollbar, left on a horizontal scrollbar). -
:increment
– The increment pseudo-class applies to buttons and track pieces. It indicates whether or not a button or track piece will increment the view’s position when used (e.g., down on a vertical scrollbar, right on a horizontal scrollbar). -
:start
– The start pseudo-class applies to buttons and track pieces. It indicates whether the object is placed before the thumb. -
:end
– The end pseudo-class applies to buttons and track pieces. It indicates whether the object is placed after the thumb. -
:double-button
– The double-button pseudo-class applies to buttons and track pieces. It is used to detect whether a button is part of a pair of buttons that are together at the same end of a scrollbar. For track pieces it indicates whether the track piece abuts a pair of buttons. -
:single-button
– The single-button pseudo-class applies to buttons and track pieces. It is used to detect whether a button is by itself at the end of a scrollbar. For track pieces it indicates whether the track piece abuts a singleton button. -
:no-button
– Applies to track pieces and indicates whether or not the track piece runs to the edge of the scrollbar, i.e., there is no button at that end of the track. -
:corner-present
– Applies to all scrollbar pieces and indicates whether or not a scrollbar corner is present. -
:window-inactive
– Applies to all scrollbar pieces and indicates whether or not the window containing the scrollbar is currently active. (In recent nightlies, this pseudo-class now applies to ::selection as well. We plan to extend it to work with any content and to propose it as a new standard pseudo-class.)
Examples of these combinations
::-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 */ }
Mozilla
Mozilla does have some extensions for manipulating the scroll-bars but they are all recommended not to be used.
-
-moz-scrollbars-none
They recommend using overflow:hidden in place of this. -
-moz-scrollbars-horizontal
Similar to overflow-x -
-moz-scrollbars-vertical
Similar to overflow-y -moz-hidden-unscrollable
Only works internally within a users profile settings. Disables scrolling XML root elements and disables using arrow keys and mouse wheel to scroll web pages.
Further details about Mozilla
This is not really useful as far as I know, but it's worth noting that the attribute which controls whether or not scrollbars are displayed in Firefox is: (reference link)
- Attribute: scrollbars
- Type: nsIDOMBarProp
- Description: The object that controls whether or not scrollbars are shown in the window. This attribute is "replaceable" in JavaScript. Read only
Last but not least, padding is like magic.
As has been previously mentioned in some other answers, here is an illustration which is sufficiently self-explanatory.