Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap modal has a flaw

As I was learning bootstrap and trying out the example on the official page, I found a flaw (maybe) with the modal component.

Click the "Launch demo modal", you will notice there is a notable margin on the top right corner, and the navbar will stretch/shrink when the modal dialog disappear/appear.

Is that a bug or intentional? I think it's annoying, How to disable it?

like image 945
adamsmith Avatar asked Aug 31 '13 15:08

adamsmith


People also ask

Is Bootstrap modal responsive?

Bootstrap modals are supposed to be responsive by default. Something to look out for is if you have a width set on your Modal. For example I had a form body container inside of my modal with a height of 40rem.

When should I use Bootstrap modal?

Bootstrap Modals offer a lightweight, multi-purpose JavaScript popup that's customizable and responsive. They can be used to display alert popups, videos, and images in a website.

Can I use modal without Bootstrap?

You can implement it by using any other library for example Bulma , by using another framework that uses jquery, for example jqueryui, by using any other javascript library that could implement a modal, or by implementing it using javascript, or even with only css and html.


2 Answers

To fix this manually simply add

body.modal-open, 
.modal-open .navbar-fixed-top, 
.modal-open .navbar-fixed-bottom 
{
    margin-right: 0px;
}

to a stylesheet that is applied after the bootstrap stylesheets.

If you want to hide the scrollbar as well you can add

.modal
{
    overflow-y: auto;
}

as well.

like image 199
lilasquared Avatar answered Sep 23 '22 04:09

lilasquared


this is the best solution i found:

body.modal-open, .modal-open .navbar-fixed-top, .modal-open .navbar-fixed-bottom {
    padding-right: 0px !important;
    overflow-y: auto;
}
like image 41
Rachid O Avatar answered Sep 24 '22 04:09

Rachid O