Set bootstrap modal body height by percentage

后端 未结 5 587
傲寒
傲寒 2021-01-31 03:09

I am trying to make a modal with a body that will scroll when the content becomes too large. However, I want the modal to be responsive to the screen size. When I set the max-he

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 03:13

    The scss solution for Bootstrap 4.0

    .modal { max-height: 100vh; .modal-dialog { .modal-content { .modal-body { max-height: calc(80vh - 140px); overflow-y: auto; } } } }

    Make sure the .modal max-height is 100vh. Then for .modal-body use calc() function to calculate desired height. In above case we want to occupy 80vh of the viewport, reduced by the size of header + footer in pixels. This is around 140px together but you can measure it easily and apply your own custom values. For smaller/taller modal modify 80vh accordingly.

提交回复
热议问题