Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

horizontal scroll in bootstrap modal

Hi i am trying add a horizontal scroll bar in bootstrap modal. I know horizontal scroll bars are not a good idea but in my case i have dynamic content which can have variable width so i want to make modal body scroll-able horizontally when width exceed modal body's width.

here is what i have tried

<div class="modal-header">
<h3 class="modal-title">Decomposition</h3>

  <div class="modal-body">
  <div class="scoll-tree">
       <div class="list-group" ng-repeat="item in items"> 
          <a class="list-group-item" href="javascript:void(0);" ng-click="getChildren(item)">{{item.value}}</a>
       </div>

  </div>

</div>

CSS:

.modal-body {
     max-width: 900px;
     overflow-x: auto;
}

here is the fiddle what i have tried.. https://jsfiddle.net/4duq2svh/2/

Any help is appreciated.

Thanks in advance.

like image 957
arsinawaz Avatar asked Jun 08 '15 11:06

arsinawaz


People also ask

How do I make a bootstrap modal 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.

Can modal be scrollable?

You can also create a scrollable modal that allows scroll the modal body by adding . modal-dialog-scrollable to . modal-dialog .

How do I add a scrollbar to a modal?

Use the . modal-dialog-scrollable class to enable scrolling inside the modal.


1 Answers

check https://jsfiddle.net/4duq2svh/3/

HTML

<div class="modal-body">
    <div class="scoll-tree">
        <div class="list-group" ng-repeat="item in items"> 
            <a class="list-group-item" href="javascript:void(0);" ng-click="getChildren(item)">{{item.value}}</a>
        </div>
    </div>
</div>

CSS

.modal-body {
    max-width: 100%;
    overflow-x: auto;
}
.scoll-tree {
    width:5000px;
}

JS

var totalwidth = 190 * $('.list-group').length;

$('.scoll-tree').css('width', totalwidth);

Here I am calculating .scoll-tree width using jQuery to help horizontal scroll bar appear.

like image 108
Nilesh Mahajan Avatar answered Sep 21 '22 06:09

Nilesh Mahajan