Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the scroll bar with CSS overflow on iOS

Tags:

css

ios

ipad

Developing an iPad website I tried to use the CSS property overflow: auto to get the scrollbars if needed in a div, but my device is refusing to show them even if the two fingers scroll is working.

I tried with

overflow: auto; 

and

overflow: scroll; 

and the result is the same.

I'm only testing on an iPad (on desktop browsers works perfectly).

Any ideas?

like image 651
mat_jack1 Avatar asked Oct 02 '10 11:10

mat_jack1


People also ask

How do I get scroll bar on iPhone?

Open a web page or document. 3. Swipe up to display the scroll bar on the right side of the page.

How do I show the scroll bar only on overflow?

Use overflow: auto . Scrollbars will only appear when needed. (Sidenote, you can also specify for only the x, or y scrollbar: overflow-x: auto and overflow-y: auto ).

How do I show the scroll bar on Mac CSS?

Showing scroll bars on Mac Windows and Linux always show you the scroll bars, but if you're on Mac you have to change a setting to get them to show. Go to System Preferences, then General and toggle “Show scroll bars” to “Always”.


2 Answers

Edit following the comment left, kindly, by kritzikratzi:

[Starting] with ios 5beta a new property -webkit-overflow-scrolling: touch can be added which should result in the expected behaviour.

Some, but very little, further reading:

  • Native momentum scrolling in iOS 5


Original answer, left for posterity.

Unfortunately neither overflow: auto, or scroll, produces scrollbars on the iOS devices, apparently due to the screen-width that would be taken up such useful mechanisms.

Instead, as you've found, users are required to perform the two-finger swipe in order to scroll the overflow-ed content. The only reference, since I'm unable to find the manual for the phone itself, I could find is here: tuaw.com: iPhone 101: Two-fingered scrolling.

The only work-around I can think of for this, is if you could possibly use some JavaScript, and maybe jQTouch, to create your own scroll-bars for overflow elements. Alternatively you could use @media queries to remove the overflow and show the content in full, as an iPhone user this gets my vote, if only for the sheer simplicity. For example:

<link rel="stylesheet" href="handheld.css" media="only screen and (max-device width:480px)" /> 

The preceding code comes from A List Apart, from the same article linked-to above (I'm not sure why they left of the type="text/css", but I assume there are reasons.

like image 187
David Thomas Avatar answered Sep 20 '22 18:09

David Thomas


Apply this code in your css

::-webkit-scrollbar{      -webkit-appearance: none;     width: 7px;  }  ::-webkit-scrollbar-thumb {      border-radius: 4px;     background-color: rgba(0,0,0,.5);      -webkit-box-shadow: 0 0 1px rgba(255,255,255,.5); } 
like image 42
Prafull Avatar answered Sep 21 '22 18:09

Prafull