Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: In a modal dialog, how do I make the dropdown menu expand outside the dialog?

Example code:

http://jsfiddle.net/vpg5g/

I'd like to have the menu that drops down from the button expand over the modal's borders. As you see, the current state is unusable. Is there some way to achieve this?

like image 431
flyx Avatar asked Aug 10 '12 10:08

flyx


People also ask

How do I make modal content scrollable?

Bootstrap 4.3 added new built-in scroll feature to modals. This makes only the modal-body content scroll if the size of the content would otherwise make the page scroll. To use it, just add the class modal-dialog-scrollable to the same div that has the modal-dialog class.

How do you increase the width of a modal dialogue?

Change the size of the modal by adding the . modal-sm class for small modals, . modal-lg class for large modals, or . modal-xl for extra large modals.

How do I toggle a drop down menu?

dropdown class indicates a dropdown menu. To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute.

How do I add a drop down menu to the navigation bar in Bootstrap?

Example Explained. Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.


2 Answers

The modal does not allow any overflowing, you can fix it by using :

.modal { overflow: visible; } .modal-body { overflow-y: visible; } 

Working demo

You may want to add a class to apply those rules only to modals that really need it, in case this fix creates bugs.

like image 181
Sherbrow Avatar answered Oct 10 '22 23:10

Sherbrow


If you cannot remove the overflow: auto You can do something like this

    $('.drop-down-inside-modal').on('click' , '.dropdown-toggle', function(event){         var self = $(this);         var selfHeight = $(this).parent().height();         var selfWidth = $(this).parent().width();         var selfOffset = $(self).offset();         var selfOffsetRigth = $(document).width() - selfOffset.left - selfWidth;         var dropDown = self.parent().find('ul');         $(dropDown).css({position:'fixed', top: selfOffset.top + selfHeight , left: 'auto', right: selfOffsetRigth ,  width: '160px'});     });      function fixDropdownPosition(){         var openDropdownButton = $('.drop-down-inside-modal.open');         if($(openDropdownButton).length){             var selfHeight = $(openDropdownButton).height();             var selfWidth = $(openDropdownButton).width();             var openDropdownButtonOffset = $(openDropdownButton).offset();             var openDropdownButtonOffsetRigth = $(document).width() - openDropdownButtonOffset.left - selfWidth;             var openDropdown = $(openDropdownButton).find('ul');             $(openDropdown).css({position:'fixed', top: openDropdownButtonOffset.top + selfHeight , left: 'auto' , right: openDropdownButtonOffsetRigth, width: '160px'});         };     };      $(".modal-body").unbind("scroll");     $(".modal-body").scroll(function(){         fixDropdownPosition();     });      $( window ).resize(function() {         fixDropdownPosition();     }); 
like image 31
ppollono Avatar answered Oct 11 '22 00:10

ppollono