I am almost done with a simple 2-page website for my registered domain names. Unfortunately I have one small issue I can't seem to fix: a jumpy header when a Twitter Bootstrap modal opens and closes. On mobile devices there's no problem. The problem only occurs in larger viewports like desktops and laptops.
How to recreate
- Open http://www.domains.cloudlabz.nl/domains in a webbrowser and make sure you get a vertical scrollbar by lowering the viewport height.
- Click on one of the blue 'more info' buttons.
- Notice the jumping header and disappearing scrollbar once the modal opens.
- Close the modal and notice the header jumping back and the scrollbar reappearing.
Check the following image (same result in Opera, Safari, Firefox and Chrome):
What I'd like
I'd like the header to stop jumping when opening/closing a modal. The fact the scrollbar disappears is not an issue. Actually, I would like it to stay like that.
Update
I noticed the jumping header only occurs with fixed position elements such as my header (added Bootstrap class navbar-fixed-top). It even occurs on the Bootstrap website itself: http://getbootstrap.com/javascripts. Go to the 'Modals > Optional Sizes' area on a desktop and click one of the buttons. You'll see the right side menu jumping back and forth.
When the modal opens, the class .modal-open is added to the body element (thanks for pointing that out @Pred). It adds a padding of 15px to the right, which is the same width as the scrollbar gutter. This prevents the body from jumping back and forth.
Unfortunately this padding apparently does not apply to fixed elements.
Add the following to your CSS:
For Bootstrap 4
sticky-top
, use the following snippet. Tested all the CSS solutions on this page but none worked for Bootstrap 4.My page design was as follows
All this happens because of this part of code in bootstrap.js:
That annoying problem happens in Firefox 32.0 (Gecko/20100101) and Chromium Version 37.0.2062.94 (Webkit 537.36) (Ubuntu 14.04). Not happens in QupZilla Version 1.6.6 (WebKit 537.21).
For me, the dirty fix is to comment the conditional line, after that it works in all browsers I tested (including some android's browsers).
NOTE: if you comment that line, you should be careful with the size of your modals since bootstrap will not create enough space for the new scrollbar.
Regards.
In my case, it can be solved by adding comments or remove these two lines
right: 0;
andleft: 0;
in bootstrap.css file:Note: I use bootstrap v3.3.7
As you usually put Bootstrap
navbar
as a direct child of thebody
container:You can use the
body
padding-right
value, calculated in the Bootstrap core code to prevent it from "jumping" when opening a modal window, to fix thenavbar
issue as well . A pure CSS solution is below:Easy as that.
I have a structure:
I'm using this CSS: