30

Can you make the overflow content of a div scrollable in the Android browser?

It is scrollable in all other modern browsers.

In iOS it is scrollable - however it does not show scrollbars - but it is scrollable via dragging.

A simple example: http://jsfiddle.net/KPuW5/1/embedded/result/

Will this be fixed soon?

2
  • 2
    It is a bug: code.google.com/p/android/issues/detail?id=6864 There are several work-arounds: cubiq.org/iscroll-4 Rather than these hacks - the bug should be fixed, with all the hype around HTML I am surprised how poorly it is implemented.
    – mercador
    Nov 4, 2011 at 18:49
  • this seems to be fixed now. some SDKs don't have the latest webviews and can still have this issue though
    – neaumusic
    Aug 17, 2015 at 6:10

5 Answers 5

25

Android 3.0 and higher have support for overflow:scroll, on < 3.0 it's another story. You might have some success with polyfills like iScroll, however that does come at a cost. It's difficult to implement on sites with complex layouts, and you need to a call a method everytime the content on your site changes. Memory use is also an issue: on already underpowered devices performance may lag because of these kinds of polyfills.

I would recommend a different approach: use Modernizr to detect support for overflow scrolling , add a class to your html tag and use that to rewrite your CSS so that pages scroll 'normally' instead of in a box.

/* For browsers that support overflow scrolling */
#div {
    height: 400px;
    overflow: auto;
}

/* And for browsers that don't */
html.no-overflowscrolling #div {
    height: auto;
}
1
  • 7
    I think your recommended approach is based on a misconception. Modernizr's overflowscrolling test is not for whether overflow:scroll works in the browser, but whether the browser has support for the *-overflow-scrolling css property, which is different.
    – speedarius
    Nov 15, 2013 at 22:13
8

overflow: scroll; is supported as of Android 3 (API 11).

For a cross-platform (namely iOS <=4.3.2) Cubiq iScroll is an easy-to-implement fix.

0
3

You could try touchscoll.js for scrollable div elements

0

Just for completeness:

The scrollbars are actually there in Android 2.3, but they are very buggy and by default they are styled to have 0 width, so they are invisible.

You can make them visible by adding styling like:

::-webkit-scrollbar {
    width: 30px;
}
::-webkit-scrollbar-track {
    background-color: $lightestgrey;
}
::-webkit-scrollbar-thumb {
    background-color: $lightgrey;
}

However, the thumb element is not draggable, you can only move it by tapping the track underneath or above it.

Also, these styles will change the look of your scrollbars in all webkit browsers, so best you should add a class that only applies to Android 2.3.

-5

You can make a DIV scrollable in Android by defining the styles of the scrollbar in your CSS. This article show you how to do it: http://css-tricks.com/custom-scrollbars-in-webkit/

4
  • Could you include a short sample here, to prevent this answer from becoming useless if/when that link goes dead? Oct 2, 2012 at 13:48
  • This does indeed show scrollbars on Android 2.3, but doesn't make the div scrollable :(
    – Husky
    Oct 2, 2012 at 13:57
  • Husky, I try it on an Android 2.3 and it works. Maybe behavior varies in different devices. Try with this webapp: applications.frenys.com/webapp/?ref=dl&app=116815031665454 (you must touch/click on the empty part of the scrollbar track)
    – juamp
    Oct 19, 2012 at 14:57
  • @juamp How does this answer the question? Jan 20, 2013 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.