_modal.scss 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // .modal-open - body class for killing the scroll
  2. // .modal - container to scroll within
  3. // .modal-dialog - positioning shell for the actual modal
  4. // .modal-content - actual modal w/ bg and corners and stuff
  5. .modal-open {
  6. // Kill the scroll on the body
  7. overflow: hidden;
  8. .modal {
  9. overflow-x: hidden;
  10. overflow-y: auto;
  11. }
  12. }
  13. // Container that the modal scrolls within
  14. .modal {
  15. position: fixed;
  16. top: 0;
  17. left: 0;
  18. z-index: $zindex-modal;
  19. display: none;
  20. width: 100%;
  21. height: 100%;
  22. overflow: hidden;
  23. // Prevent Chrome on Windows from adding a focus outline. For details, see
  24. // https://github.com/twbs/bootstrap/pull/10951.
  25. outline: 0;
  26. // We deliberately don't use `-webkit-overflow-scrolling: touch;` due to a
  27. // gnarly iOS Safari bug: https://bugs.webkit.org/show_bug.cgi?id=158342
  28. // See also https://github.com/twbs/bootstrap/issues/17695
  29. }
  30. // Shell div to position the modal with bottom padding
  31. .modal-dialog {
  32. position: relative;
  33. width: auto;
  34. margin: $modal-dialog-margin;
  35. // allow clicks to pass through for custom click handling to close modal
  36. pointer-events: none;
  37. // When fading in the modal, animate it to slide down
  38. .modal.fade & {
  39. @include transition($modal-transition);
  40. transform: $modal-fade-transform;
  41. }
  42. .modal.show & {
  43. transform: $modal-show-transform;
  44. }
  45. // When trying to close, animate focus to scale
  46. .modal.modal-static & {
  47. transform: $modal-scale-transform;
  48. }
  49. }
  50. .modal-dialog-scrollable {
  51. display: flex; // IE10/11
  52. max-height: subtract(100%, $modal-dialog-margin * 2);
  53. .modal-content {
  54. max-height: subtract(100vh, $modal-dialog-margin * 2); // IE10/11
  55. overflow: hidden;
  56. }
  57. .modal-header,
  58. .modal-footer {
  59. flex-shrink: 0;
  60. }
  61. .modal-body {
  62. overflow-y: auto;
  63. }
  64. }
  65. .modal-dialog-centered {
  66. display: flex;
  67. align-items: center;
  68. min-height: subtract(100%, $modal-dialog-margin * 2);
  69. // Ensure `modal-dialog-centered` extends the full height of the view (IE10/11)
  70. &::before {
  71. display: block; // IE10
  72. height: subtract(100vh, $modal-dialog-margin * 2);
  73. content: '';
  74. }
  75. // Ensure `.modal-body` shows scrollbar (IE10/11)
  76. &.modal-dialog-scrollable {
  77. flex-direction: column;
  78. justify-content: center;
  79. height: 100%;
  80. .modal-content {
  81. max-height: none;
  82. }
  83. &::before {
  84. content: none;
  85. }
  86. }
  87. }
  88. // Actual modal
  89. .modal-content {
  90. position: relative;
  91. display: flex;
  92. flex-direction: column;
  93. width: 100%; // Ensure `.modal-content` extends the full width of the parent `.modal-dialog`
  94. // counteract the pointer-events: none; in the .modal-dialog
  95. color: $modal-content-color;
  96. pointer-events: auto;
  97. background-color: $modal-content-bg;
  98. background-clip: padding-box;
  99. border: $modal-content-border-width solid $modal-content-border-color;
  100. @include border-radius($modal-content-border-radius);
  101. @include box-shadow($modal-content-box-shadow-xs);
  102. // Remove focus outline from opened modal
  103. outline: 0;
  104. }
  105. // Modal background
  106. .modal-backdrop {
  107. position: fixed;
  108. top: 0;
  109. left: 0;
  110. z-index: $zindex-modal-backdrop;
  111. width: 100vw;
  112. height: 100vh;
  113. background-color: $modal-backdrop-bg;
  114. // Fade for backdrop
  115. &.fade {
  116. opacity: 0;
  117. }
  118. &.show {
  119. opacity: $modal-backdrop-opacity;
  120. }
  121. }
  122. // Modal header
  123. // Top section of the modal w/ title and dismiss
  124. .modal-header {
  125. display: flex;
  126. align-items: flex-start; // so the close btn always stays on the upper right corner
  127. justify-content: space-between; // Put modal header elements (title and dismiss) on opposite ends
  128. padding: $modal-header-padding;
  129. border-bottom: $modal-header-border-width solid $modal-header-border-color;
  130. @include border-top-radius($modal-content-inner-border-radius);
  131. .close {
  132. padding: $modal-header-padding;
  133. // auto on the left force icon to the right even when there is no .modal-title
  134. margin: (-$modal-header-padding-y) (-$modal-header-padding-x) (-$modal-header-padding-y) auto;
  135. }
  136. }
  137. // Title text within header
  138. .modal-title {
  139. margin-bottom: 0;
  140. line-height: $modal-title-line-height;
  141. }
  142. // Modal body
  143. // Where all modal content resides (sibling of .modal-header and .modal-footer)
  144. .modal-body {
  145. position: relative;
  146. // Enable `flex-grow: 1` so that the body take up as much space as possible
  147. // when there should be a fixed height on `.modal-dialog`.
  148. flex: 1 1 auto;
  149. padding: $modal-inner-padding;
  150. }
  151. // Footer (for actions)
  152. .modal-footer {
  153. display: flex;
  154. flex-wrap: wrap;
  155. align-items: center; // vertically center
  156. justify-content: flex-end; // Right align buttons with flex property because text-align doesn't work on flex items
  157. padding: $modal-inner-padding - $modal-footer-margin-between / 2;
  158. border-top: $modal-footer-border-width solid $modal-footer-border-color;
  159. @include border-bottom-radius($modal-content-inner-border-radius);
  160. // Place margin between footer elements
  161. // This solution is far from ideal because of the universal selector usage,
  162. // but is needed to fix https://github.com/twbs/bootstrap/issues/24800
  163. // stylelint-disable-next-line selector-max-universal
  164. > * {
  165. margin: $modal-footer-margin-between / 2;
  166. }
  167. }
  168. // Measure scrollbar width for padding body during modal show/hide
  169. .modal-scrollbar-measure {
  170. position: absolute;
  171. top: -9999px;
  172. width: 50px;
  173. height: 50px;
  174. overflow: scroll;
  175. }
  176. // Scale up the modal
  177. @include media-breakpoint-up(sm) {
  178. // Automatically set modal's width for larger viewports
  179. .modal-dialog {
  180. max-width: $modal-md;
  181. margin: $modal-dialog-margin-y-sm-up auto;
  182. }
  183. .modal-dialog-scrollable {
  184. max-height: subtract(100%, $modal-dialog-margin-y-sm-up * 2);
  185. .modal-content {
  186. max-height: subtract(100vh, $modal-dialog-margin-y-sm-up * 2);
  187. }
  188. }
  189. .modal-dialog-centered {
  190. min-height: subtract(100%, $modal-dialog-margin-y-sm-up * 2);
  191. &::before {
  192. height: subtract(100vh, $modal-dialog-margin-y-sm-up * 2);
  193. }
  194. }
  195. .modal-content {
  196. @include box-shadow($modal-content-box-shadow-sm-up);
  197. }
  198. .modal-sm {
  199. max-width: $modal-sm;
  200. }
  201. }
  202. @include media-breakpoint-up(lg) {
  203. .modal-lg,
  204. .modal-xl {
  205. max-width: $modal-lg;
  206. }
  207. }
  208. @include media-breakpoint-up(xl) {
  209. .modal-xl {
  210. max-width: $modal-xl;
  211. }
  212. }