I have a website here.
Viewed in a desktop browser, the black menu bar properly extends only to edge of the window, since the body
has overflow-x:hidden
.
In any mobile browser, whether Android or iOS, the black menu bar displays its full width, which brings whitespace on the right of the page. As far as I can tell, this whitespace isn't even a part of the html
or body
tags.
Even if I set the viewport to a specific width in the <head>
:
<meta name="viewport" content="width=1100, initial-scale=1">
The site expands to the 1100px but still has the whitespace beyond the 1100.
What am I missing? How do I keep the viewport to 1100 and cut off the overflow?
VictorS's comment on the accepted answer deserves to be it's own answer because it's a very elegant solution that does, indeed work. And I'll add a tad to it's usefulness.
Victor notes adding
position:fixed
works.And indeed it does. However, it also has a slight side-affect of essentially scrolling to the top.
position:absolute
resolves this but, re-introduces the ability to scroll on mobile.If you know your viewport (my plugin for adding viewport to the
<body>
) you can just add a css toggle for theposition
.I also add this to prevent the underlying page from jumping left/right when showing/hiding modals.
Keep the viewport untouched:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Assuming you would like to achieve the effect of a continuous black bar to the right side:
#menubar
shouldn't exceed 100%, adjust the border radius such that the right side is squared and adjust the padding so that it extends a little more to the right. Modify the following to your#menubar
:Adjusting the
padding
to 10px of course leaves the left menu to the edge of the bar, you can put the remaining 40px to each of theli
, 20px on each side left and right:When you resize the browser smaller, you would find still the white background: place your background texture instead from your div to
body
. Or alternatively, adjust the navigation menu width from 100% to lower value using media queries. There are a lot of adjustments to be made to your code to create a proper layout, I'm not sure what you intend to do but the above code will somehow fix your overflowing bar.I've just been working on this for a few hours, trying various combinations of things from this and other pages. The thing that worked for me in the end was to make a site wrapper div, as suggested in the accepted answer, but to set both overflows to hidden instead of just the x overflow. If I leave overflow-y at scroll, I end up with a page that only scrolls vertically by a few pixels and then stops.
Just this was enough, without setting anything on the body or html elements.
I solved the issue by using overflow-x:hidden; as follows
structure is as follows
1st div end_screen >> inside it >> end_screen_2(div) >> inside it >> end_screen_2.
'end_screen is the wrapper of end_screen_1 and end_screen_2 div's
As subarachnid said overflow-x hidden for both body and html worked Here's working example
Link
This worked for me after also adding
position: relative
to the wrapper.