Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make a scrollbar always visible in a div - chrome

Tags:

css

I've implemented infinite scrolling for the first time, but I can't get the scrollbar to show up initially when there is no overflow. I tried this in chrome:

#scrollarea-invalid {
overflow-y: scroll !important;
height: 350px;
}

how can I make the scrollbar always show up in this div, even if the content is less than 350px in this div?

like image 213
devdropper87 Avatar asked Feb 26 '16 23:02

devdropper87


People also ask

How do I stop the scroll bar from disappearing in Chrome?

Open a Chrome window. In the address bar, enter "chrome://flags," and navigate to that page. Scroll down to Overlay Scrollbars, and set the field to "Disabled."

How do I make my scrollbar always visible?

Make sure overflow is set to "scroll" not "auto." With that said, in OS X Lion, overflow set to "scroll" behaves more like auto in that scrollbars will still only show when being used.

How do I stop my scroll bar from hiding?

Click on Start > Ease of Access. Scroll down on the left and Check or uncheck Automatically hide scroll bars in Windows.


3 Answers

body {    padding: 10px;  }    ul {    max-height:150px;    overflow:scroll;  }    ::-webkit-scrollbar {    -webkit-appearance: none;    width: 10px;  }    ::-webkit-scrollbar-thumb {    border-radius: 5px;    background-color: rgba(0,0,0,.5);    -webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);  }
<ul>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>      <li>This is some content</li>  </ul>
like image 183
Cumulo Nimbus Avatar answered Oct 14 '22 00:10

Cumulo Nimbus


Just having the scrollbar visible will not allow you to react to the user trying to scroll down. So you will need to actually make the content flow outside of the area and detect the scroll.
Try this:

#scrollarea-invalid { overflow-y: scroll; height: 350px; } #scrollarea-content{   min-height:101%; }
<div id='scrollarea-invalid'>   <div id='scrollarea-content'></div> </div>
like image 37
trex005 Avatar answered Oct 14 '22 02:10

trex005


overflow: auto or overflow: scroll won't sometimes work. So we have to try webkit based code to resolve this issue.

Try the following code to display scroll bar always shown,

::-webkit-scrollbar {
  -webkit-appearance: none;
  width: 10px;
}

::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background-color: rgba(0,0,0,.5);
  -webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);
}

this will always show the vertical and horizontal scroll bar on your page. If you need only a vertical scroll bar then put overflow-x: hidden

like image 36
Codemaker Avatar answered Oct 14 '22 02:10

Codemaker