Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent horizontal scroll on jQuery Mobile

Is there a way to prevent horizontal page scroll on a mobile device preferably with CSS only?

Here's an example: http://jsfiddle.net/YfLst/15/

Update: The following code solves the issue on iOS but the problem remains on Android:

html, body {
    overflow-x: hidden !important;
    position: relative !important;
}
like image 873
Diogo Cardoso Avatar asked May 20 '26 17:05

Diogo Cardoso


1 Answers

There are different ways to do that:

You could target mobile devices with a special stylesheet

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

And set the body width to 100% and overflow-x: hidden, or even try to position it absolutely

body {
  width: 100%;
  overflow-x: hidden;
  position: absolute;
  top: 0;
  left: 0;
}

in css.

If by "preventing horizontal scrolling" you mean that your viewport (the area displayed on the mobile screen) is too narrow and should be bigger, you should set the viewport width accordingly in your meta tags

    <meta content="width = 999 (for example)" name="viewport">
like image 120
Beat Richartz Avatar answered May 22 '26 07:05

Beat Richartz