Bootstrap modal body max height 100%

后端 未结 10 1802
梦如初夏
梦如初夏 2020-12-31 06:37

I have a custom sized (80% height width) bootstrap modal body and it scrolls (body content will overflow on some sized screens)

There are 2 problems:

  1. I
10条回答
  •  北海茫月
    2020-12-31 07:22

    Here is a fully working Sass solution, but it requires flexbox.

      // don't clamp modal height when screen is shorter than 400px
      // .modal-body is short in that case, and the default behavior
      // (entire modal will scroll) is easier to use
      @media(min-height:400px)
        .modal
          // use top/bottom margin here instead of .modal-dialog
          // so that .modal-dialog can use height: 100%
          margin: 30px
          // without overflow: visible the shadow will be clipped
          // at the bottom
          overflow: visible
    
          > .modal-dialog
            margin: 0 auto
            // height must be explicitly set for .modal-content to
            // use percentage max-height
            height: 100%
    
            > .modal-content
              display: flex
              flex-direction: column
              max-height: 100%
    
              > .modal-header,
              > .modal-footer,
                // don't allow header/footer to grow or shrink
                flex: 0 0 auto
    
              > .modal-body
                // allow body to shrink but not grow
                flex: 0 1 auto
                // make body scrollable instead of entire modal
                overflow-y: auto
    

提交回复
热议问题