How to put scroll bar only for modal-body?

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

I have the following element:

13条回答
  •  孤街浪徒
    2020-11-30 18:32

    I know this is an old topic but this may help someone else.

    I was able to make the body scroll by making the modal-dialog element position fixed. And since I would never know the exact height of the browser window, I took the information I was sure about, the height of the header and the footer. I was then able to make the modal-body element's top and bottom margins match those heights. This then produced the result I was looking for. I threw together a fiddle to show my work.

    also, if you want a full screen dialog just un-comment the width:auto; inside the .modal-dialog.full-screen section.

    https://jsfiddle.net/lot224/znrktLej/

    And here is the css that I used to modify the bootstrap dialog.

    .modal-dialog.full-screen {
        position:fixed;
        //width:auto;  // uncomment to make the width based on the left/right attributes.
        margin:auto;                        
        left:0px;
        right:0px;
        top:0px;
        bottom:0px;
    }
    
    .modal-dialog.full-screen .modal-content {
          position:absolute;
          left:10px;
          right:10px;
          top:10px;
          bottom:10px;
    }
    
    .modal-dialog.full-screen .modal-content .modal-header {
            height:55px;  // adjust as needed.
    }
    
    .modal-dialog.full-screen .modal-content .modal-body {
            overflow-y: auto;
              position: absolute;
              top: 0;
              bottom: 0;
            left:0;
            right:0;
              margin-top: 55px; // .modal-header height
              margin-bottom: 80px;  // .modal-footer height
    }
    
    .modal-dialog.full-screen .modal-content .modal-footer {
            height:80px;  // adjust as needed.
            position:absolute;
            bottom:0;
            left:0;
            right:0;
    }
    

提交回复
热议问题