bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Open modal is shifting body content to the left

Open AS-OLD opened this issue 13 years ago • 120 comments

When launching the modal component (http://getbootstrap.com/javascript/#modals) the entire content will slightly move to the left on mac OS (haven't tried it on windows yet). With the active modal the scrollbar seem to disappear, while the content width still changes.

You can observer the problem on the bootstrap page

AS-OLD avatar Aug 19 '13 16:08 AS-OLD

I can confirm that I see this also on Chrome for Linux, both on getbootstrap.com and on the 3.0.0-wip branch

jamescostian avatar Aug 19 '13 16:08 jamescostian

@jamescostian If you mean on the CDN, that's outdated. Could you clarify whether you mean git or the CDN?

cvrebert avatar Aug 19 '13 17:08 cvrebert

@cvrebert Via git. I even rebuilt the JS, and it's still doing this.

jamescostian avatar Aug 19 '13 17:08 jamescostian

Yup, saw this as well when I enabled scrollbars all the time in OS X. /cc @fat

mdo avatar Aug 19 '13 17:08 mdo

kicking this back to @mdo – how twitter gets around this is they add a 15px margin to the right. and some other tricky css hacks…

@mdo you can just use the modal-open class to style the body as twitter has

fat avatar Aug 19 '13 19:08 fat

This fix causes the page to jump 15px to the left when a modal is opened on desktop and iOS Safari. In those environments there is normally no scrollbar to cover - and who says a scrollbar is always going to be 15px?!

Before (blur to cover private content):

(image removed)

After:

(image removed)

You can see the extra 15px on the right - look at the navbar. What isn't so obvious is that the body text has also moved to the left. Same problem on desktop Safari.

chrisseaton avatar Aug 19 '13 23:08 chrisseaton

Also happens on OS X Chrome.

cvrebert avatar Aug 20 '13 01:08 cvrebert

This is #9886

Merg1255 avatar Aug 20 '13 02:08 Merg1255

Confirmed on OS X 10.8 Chrome, when scroll bars are always on: screen shot 2013-08-20 at 11 44 04 am

Also confirmed on Windows 7 Chrome & IE10.

tnorthcutt avatar Aug 20 '13 16:08 tnorthcutt

Okay, so what Twitter does now is they run a script to determine the width of the scrollbar and then apply conditional CSS to adjust the modal and page contents accordingly. They know when say OS 10.8 has scrollbars visible when scrolling vs always visible, for example. It's truly the only way of making it happen.

So, no matter what, we need some scripting to help us apply the styles.

/cc @fat

mdo avatar Aug 24 '13 06:08 mdo

@mdo the modal already needs some scripting to be functional.

Merg1255 avatar Aug 24 '13 10:08 Merg1255

Oh crap! duplicated multiple times!, my bad. Apologies

luishdez avatar Aug 29 '13 18:08 luishdez

EDIT: Modal was created from the example in the docs and I copied the repo and used the css and js files from the dist directory.

After lots of tweaking and testing, the shift still occurs (on Win7 Pro Chrome (29) and Firefox (22) and iPad Safari (6.1.3)), I came to this conclusion:

If the body has already scrolling, there is no shifting, but, if the modal overflow-y is 'scroll' and the body hasn't got a scrollbar, then it shifts.

huwcbjones avatar Aug 30 '13 14:08 huwcbjones

There are some pixels added even if the body already has scrolling, and that's on 15" screens. For some reason those pixels are added on the body, even if the modal can fit inside the current screen size.

Merg1255 avatar Aug 30 '13 14:08 Merg1255

http://i41.tinypic.com/2s0e05x.jpg

Merg1255 avatar Aug 30 '13 14:08 Merg1255

+1 form me too!

i'm on osx:

using firefox, the everything seems ok, the scrollbar takes an actual 15px of the viewport. when the modal is opened, the scroll-y gets hidden and the 15px shift correctly keeps the website in place (if the shift wouldnt be there, the website would jump 15px to the right).

using chrome, its different. the scrollbar in chrome does not take an actual 15px of the viewport... its like an overlay here. opening the modal still triggers the 15px shift, which is in that case not correct

maybr this clarifies the issue

ctaepper avatar Aug 30 '13 20:08 ctaepper

Just confirming that this is still an issue. Tested on OSX safari, chrome, firefox.

jamesmfriedman avatar Sep 01 '13 21:09 jamesmfriedman

This does not happen with v2.x.x So can't we use the same method to display the modal as in 2.x.x?

ghost avatar Sep 01 '13 21:09 ghost

As far as I know the reason it's different to v2 is so that scrolling works better - you can now scroll the page as normal, with the modal setting the limits, rather than having to scroll within the modal if it overflows, which on scrollbar-less systems is particularly bad as you would never know there was overflow-scroll hidden content as you can see the whole model so why would you think some part of it needed to be scrolled?

I know that the final RC worked perfectly for me, and that this change came between that final RC and the release.

My proposed solution is to make the fade cover the whole page, and let you scroll the page as normal, with the modal given an absolute position rather than its own scroll area within the fade. https://github.com/twbs/bootstrap/pull/9339

chrisseaton avatar Sep 01 '13 21:09 chrisseaton

This bug is pretty much single-handedly destroying modal performance on the built-in browsers in the 10.1" Galaxy Note 2, the 7.0" Galaxy Tab 2 and significantly crippling it in Chrome on the 2012 Nexus 7 and the Galaxy Nexus; recalculating the entire page style to account for the extra padding on the right will lag the browser.

Removing .fade from the modal helps a little.

tvararu avatar Sep 08 '13 00:09 tvararu