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?

mercador
  • 745
  • 2
  • 8
  • 14
  • 2
    It is a bug: http://code.google.com/p/android/issues/detail?id=6864 There are several work-arounds: http://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 04 '11 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 '15 at 06:10

5 Answers5

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;
}
Husky
  • 4,744
  • 2
  • 37
  • 38
  • 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 '13 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.

Alastair
  • 6,451
  • 3
  • 33
  • 29
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.

emik
  • 833
  • 12
  • 11
-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/

juamp
  • 1
  • Could you include a short sample here, to prevent this answer from becoming useless if/when that link goes dead? – Andrew Barber Oct 02 '12 at 13:48
  • This does indeed show scrollbars on Android 2.3, but doesn't make the div scrollable :( – Husky Oct 02 '12 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: http://applications.frenys.com/webapp/?ref=dl&app=116815031665454 (you must touch/click on the empty part of the scrollbar track) – juamp Oct 19 '12 at 14:57
  • @juamp How does this answer the question? – hitautodestruct Jan 20 '13 at 21:00