Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent horizontal scrolling on responsive webpage?

Tags:

I'm using twitter bootstrap to make my app responsive. When I shrink the width of my browser window to the minimum size or view the page on a mobile device (iPhone, example), the user is able to scroll horizontally. The amount of horizontal scroll is small but I would like to remove it all together.

I believe it's due to the img container that I'm including, but I'm not here. The page's html is located here: http://pastebin.ca/2347946.

Any advice on how to prevent the horizontal scroll for the page while still maintaining the scrolling in the img container?

like image 669
sharataka Avatar asked Apr 02 '13 16:04

sharataka


People also ask

How do I stop my web page from scrolling horizontally on my phone?

In some instances, using overflow: hidden; will lock your page at the top, with no ability to scroll down. As Mikeys4u relates, it's usually better to use overflow-x: hidden; .

Why am I getting a horizontal scrollbar on my website?

That makes sense — if you specify a fixed width of 3000px in the CSS, someone at 1920x1080 resolution will only see the left-hand 1920 pixels of the content on the website. On the right side, there is “horizontal overflow,” so you'll see horizontal scrollbars.


2 Answers

I had the same problem, and applied this to fix it:

body {     overflow-x: hidden !important; } .container {     max-width: 100% !important;     overflow-x: hidden !important; } 

To expand a bit, I only had the problem on mobile phones, so this is my final code:

@media screen and (max-width: 667px) {     body {         overflow-x: hidden !important;     }     .container {         max-width: 100% !important;         overflow-x: hidden !important;     } } 

I found the issues regarding this on Github, so I guess newer versions of Bootstrap have been patched.

like image 186
The Onin Avatar answered Nov 10 '22 00:11

The Onin


i am pretty sure somewhere one of your child element is exceeding the width of its parent element. Check you code twice, if there any box-size of inner child elements is large because of one of the reasons like- when the box width including margin, padding, border go beyond the limit. And we possibly haven't added overflow: hidden; to its outer parent element. In this case they are considered reaching beyond their parent element and browsers show it with the scrollbar. So fix it via removing extra margins, paddings, borders or if you just don't want any headache, just try to add overflow:hidden; to the outer box.

like image 26
Akshaya Raghuvanshi Avatar answered Nov 10 '22 00:11

Akshaya Raghuvanshi