How to put scroll bar only for modal-body?

后端 未结 13 1172
悲哀的现实
悲哀的现实 2020-11-30 18:14

I have the following element:

相关标签:
13条回答
  • 2020-11-30 18:20

    In latest bootstrap version there is a class to make modal body scrollable.

    .modal-dialog-scrollable to .modal-dialog.

    Bootstrap modal link for modal body scrollable content

    <!-- Scrollable modal -->
    <div class="modal-dialog modal-dialog-scrollable">
      ...
    </div>
    
    0 讨论(0)
  • 2020-11-30 18:22

    Or simpler you can put between your tags first, then to the css class.

    <div style="height: 35px;overflow-y: auto;"> Some text o othre div scroll </div>
    
    0 讨论(0)
  • 2020-11-30 18:23

    You have to set the height of the .modal-body in and give it overflow-y: auto. Also reset .modal-dialog overflow value to initial.

    See the working sample:

    http://www.bootply.com/T0yF2ZNTUd

    .modal{
        display: block !important; /* I added this to see the modal, you don't need this */
    }
    
    /* Important part */
    .modal-dialog{
        overflow-y: initial !important
    }
    .modal-body{
        height: 80vh;
        overflow-y: auto;
    }
    
    0 讨论(0)
  • 2020-11-30 18:25

    In your modal body you have to set a height, it can be % vh or calc:

    modal-body {
        height: 80vh;
        overflow-x: auto;
    }
    

    or

    modal-body {
        height: calc(100vh - 5em);
        overflow-x: auto;
    }
    

    In my case look like:

    0 讨论(0)
  • 2020-11-30 18:28

    Adding on to Carlos Calla's great answer.

    The height of .modal-body must be set, BUT you can use media queries to make sure it's appropriate for the screen size.

    .modal-body{
        height: 250px;
        overflow-y: auto;
    }
    
    @media (min-height: 500px) {
        .modal-body { height: 400px; }
    }
    
    @media (min-height: 800px) {
        .modal-body { height: 600px; }
    }
    
    0 讨论(0)
  • 2020-11-30 18:30

    If you're only supporting IE 9 or higher, you can use this CSS that will smoothly scale to the size of the window. You may need to tweak the "200px" though, depending on the height of your header or footer.

    .modal-body{
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }
    
    0 讨论(0)
提交回复
热议问题