Hide vertical scrollbar whilst remaining scrollable - html

I want the vertical scrollbar for my div to be invisible, but still allow vertical scrolling.
I've tried using overflow-y: hidden but that disables scrolling.
I've tried webkit element::-webkit-scrollbar but that affects horizontal scrollbars too.
I would have thought that webkit's :vertical state would allow me to do it but it doesn't do anything. See codepen: (https://codepen.io/numberjak/pen/MWgOMqd)
Other questions look at BOTH scrollbars, I just care about ONE scrollbar.
<div class="scroll"><div class="large-content"/></div>
.scroll {
overflow: auto;
max-width: 20rem;
max-height: 20rem;
background-color: black;
}
.scroll::-webkit-scrollbar:vertical {
display: none;
}
.large-content {
min-width: 100rem;
min-height: 100rem;
background-color: red;
}

Try this css code..
css
.large-content {
background-color: red;
width: 100%;
height: 100%;
}

You can do the following to hide scrollbars:
-webkit- (Chrome, Safari, newer versions of Opera):
.scoll::-webkit-scrollbar { width: 0 !important; }
-moz- (Firefox):
.scroll { overflow: -moz-scrollbars-none; }
-ms- (Internet Explorer +10):
.scroll { -ms-overflow-style: none; }
Important points to be considered before hiding the scroll bar:
Preferably hide scrollbars only if and when all content is visible else the user may skip the content.
Avoid horizontal scrolling on web pages and do not hide horizontal scroll bar as they can make content difficult to read
If at all, hiding scroll is required: Display all important information above the fold. Users may often decide if they want to stay or not on what they can see without scrolling.
Reference

Related

How to hide scroll bar without using overflow "hidden"?

image1
in this image, there is no scroll bar but if I scroll down inside diagram component div element scrollbar will occur
image2 with scrollbar
how can I hide that scrollbar without setting overflow: hidden
references
Just use the CSS of it like that:
selector-with-overflow::-webkit-scrollbar {
width: 10px;
visibility: hidden;
display: none;
}
notice doesnt work on all browsers but should work on the most common ones
I'm not sure why you'd ever want to hide the indication that a page is overflowing, see this JSFiddle: http://jsfiddle.net/2nT38/868/ for the css for a scrollbar that isn't visible yet still scrollable. Here's the breakdown:
::-webkit-scrollbar {
-webkit-appearance: none;
}
::-webkit-scrollbar:vertical {
width: 0px;
}
::-webkit-scrollbar:horizontal {
height: 0px;
}
Hope this helps!

Only Enable Scrollbar on Body And Disable on Other Div with CSS HTML

Is there a way to only enable scrollbar on the body only and disable on other divs?
This code disables all scrollbar in everywhere:
::-webkit-scrollbar {
display:none;
}
How to enable only on the body?
EDITED
Changing overflow is not the one I want. Let's say I want to create mobile friendly view editor, which able to scroll up and down inside the div content but the scrollbar should be hidden. The scrollbar in the body is necessary because I will have to edit the view from my desktop web browser.
Changing overflow will not help in this case.
These two CSS properties can be used to hide the scrollbars:
#parent{
height: 100%;
width: 100%;
overflow: hidden;
}
#child{
width: 100%;
height: 100%;
overflow-y: scroll;
}
jsfiddle: http://jsfiddle.net/5GCsJ/954/

Hiding WebKit scrollbar when overflow-scrolling: touch is enabled

As we all know, you can hide a scrollbar in Safari and Chromium with the following CSS snippet:
::-webkit-scrollbar {
display: none;
}
However, this doesn't seem to work when -webkit-overflow-scrolling is set to touch, specifically on iOS. Chromium properly hides the scrollbar.
Is this a WebKit bug, or is there a way to hide a scrollbar AND enable fluid (touch) scrolling? It seems to be possible (perhaps with js?), on the mobile version of Google. Looking through the page source and googling my answer didn't seem to help though.
It seems that currently (as of January 2017) the only way to get around this is by wrapping the scrollable element inside of a parent div and manually hiding the scrollbar from view.
This can be achieved by applying a fixed height/width and overflow: hidden; to the parent div. You can then add extra padding or height/width to the original element to, essentially, push the scrollbar out of view.
Mark Otto tweeted about the issue back in June 2016. Here is an example of his workaround: https://output.jsbin.com/lohiga.
The basic idea goes something like this:
<header>
<div> <!-- parent wrapper added -->
<nav>
First link
Link
Link
Link
Link
Link
Link
Link
Last link
</nav>
</div>
</header>
CSS:
header {
margin: 20px 0;
padding: 10px 5px;
text-align: center;
background-color: #f5f5f5;
border-bottom: 1px solid #ddd;
}
// Parent wrapper
div {
height: 30px;
overflow-y: hidden; // "crop" the view so the scrollbar can't be seen
}
// Original scrollable element
nav {
padding-bottom: 20px; // extra padding to push the scrollbar out of view
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
nav a {
display: inline-block;
padding: 5px 10px;
}

Fixed elements aren't clickable when I quickly scroll to the bottom in iOS Safari 9+

I've run into a very annoying issue only on iOS Safari 9+ (8.4 is fine) where, once the user quickly scrolls a page resulting in anchor links within fixed elements no longer being clickable due to the appearance and actual click/hit area not lining up with its element until the user scrolls again.
It doesn't happen the same way every time, and can take a few tries to "break" the system. Content must be longer than the viewport for this to work.
No workarounds to the problem yet. How can I solve this issue?
UPDATE: After further testing, the issue only happens with iOS Safari 9 and above, tested on iOS 8 and there is no problem.
UPDATE 2: It's now clear that this happens on most websites using position:fixed; and even position:-webkit-sticky;. You may want to check yours :)
HTML
<section>
<article></article>
<article></article>
<article></article>
</section>
<div class="sticky">
</div>
CSS:
html, body {
margin:0;
}
article {
display: block;
height: 200px;
width: 100%;
margin-bottom: 20px;
background: whitesmoke;
}
.sticky {
width:100%;
height:100px;
position: fixed;
bottom:0;
background: orange;
text-align:center;
}
.sticky a {
display: inline-block;
width: 100px;
height: 100px;
background: yellow;
}
http://codepen.io/toobulo/pen/dGEodo
The issue doesn't happen within Codepen editor, as it's related to mobile Safari's elastic / toolbar size changes. Please export code into own page, or use the following link:
https://cdn.rawgit.com/anonymous/3234ad797dd80e5f8905/raw/ab51c4d8621cfb827f83a33d21940579f8682cde/index.html
This problem is related to the bounce effect in ios and losing the toolbar & the header bar. The only way that i have found to fix this is to do the following:
html,
body {
height: 100%;
width: 100%;
overflow: auto;
-webkit-overflow-scrolling: auto
}
You could do it on a breakpoint as well so it only works for mobile. Hope this helps.
** Added the overflow scrolling.
I found that andy jones's answer effectively fixed this problem for me, but it had an unwelcome side effect: momentum scrolling no longer worked. This made scrolling down long pages on an iPad take forever.
Combining andy's answer with this tidbit from CSS tricks made my links clickable while also allowing for momentum scrolling:
html,
body {
height: 100%;
overflow-y: scroll; /* must be scroll, not auto */
-webkit-overflow-scrolling: touch;
}
I also found that the width: 100% style from andy's answer was unnecessary, so I removed that as well.
You can make .sticky a link absolute and apply following CSS so the link will be independent to the window/browser.
.sticky {
width: 50px;
}
.sticky a {
position: absolute;
top: 0;
bottom: 0;
margin: auto;
}

Scrollbars not hiding

I've recently stumbled upon a rather interesting behavior related to browser scrollbars. Here is the link to demonstrate this: http://jsfiddle.net/5L7tyswh/5/
HTML:
<div class='container'>
<div class='fix' />
</div>
CSS:
body {
margin: 0;
}
.container {
position: absolute;
overflow: auto;
width: 100%;
height: 100%;
max-height: 400px;
max-width: 400px;
}
.noscroll {
overflow: hidden;
}
.fix {
width: 400px;
height: 400px;
background-color: green;
}
So the situation is basically this: I want a fixed sized div that is scrollable if the window becomes smaller than the minimum. I explicitly want the scrollbars to appear 'in the div' so I created a container that acts as the 'scrollpanel'. So far so good.
The strangeness comes when you shrink the window small enough for the scrollbars to show up, then enlarge it again. What happens is that the scrollbars don't hide as they should (at least I think it would be logical). I don't know if it is a bug or a feature, but my tip is on the former. My only explanation to this is that the vertical and horizontal scrollbars prevent each other from disappearing.
The workaround is the commented javascript, if you uncomment it the scrollbars behave as they meant to.
Can anyone explain this better?
Update:
I can only reproduce it in Chrome so far. It works in IE11 and Firefox.
Looks like a bug or a peculiarity of Chrome ;)
You can prevent the behavior in Chrome without javaScript and extra classes by using #media directive in your css
#media screen and (min-width: 400px) {
.container {
overflow: hidden;
}
}
This prevents the scrollbars to appear when the window is bigger than 400px. Works on all (recent) browsers.