_modal.scss 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 { opacity: 0; }
  116. &.show { opacity: $modal-backdrop-opacity; }
  117. }
  118. // Modal header
  119. // Top section of the modal w/ title and dismiss
  120. .modal-header {
  121. display: flex;
  122. align-items: flex-start; // so the close btn always stays on the upper right corner
  123. justify-content: space-between; // Put modal header elements (title and dismiss) on opposite ends
  124. padding: $modal-header-padding;
  125. border-bottom: $modal-header-border-width solid $modal-header-border-color;
  126. @include border-top-radius($modal-content-inner-border-radius);
  127. .close {
  128. padding: $modal-header-padding;
  129. // auto on the left force icon to the right even when there is no .modal-title
  130. margin: (-$modal-header-padding-y) (-$modal-header-padding-x) (-$modal-header-padding-y) auto;
  131. }
  132. }
  133. // Title text within header
  134. .modal-title {
  135. margin-bottom: 0;
  136. line-height: $modal-title-line-height;
  137. }
  138. // Modal body
  139. // Where all modal content resides (sibling of .modal-header and .modal-footer)
  140. .modal-body {
  141. position: relative;
  142. // Enable `flex-grow: 1` so that the body take up as much space as possible
  143. // when there should be a fixed height on `.modal-dialog`.
  144. flex: 1 1 auto;
  145. padding: $modal-inner-padding;
  146. }
  147. // Footer (for actions)
  148. .modal-footer {
  149. display: flex;
  150. flex-wrap: wrap;
  151. align-items: center; // vertically center
  152. justify-content: flex-end; // Right align buttons with flex property because text-align doesn't work on flex items
  153. padding: $modal-inner-padding - $modal-footer-margin-between / 2;
  154. border-top: $modal-footer-border-width solid $modal-footer-border-color;
  155. @include border-bottom-radius($modal-content-inner-border-radius);
  156. // Place margin between footer elements
  157. // This solution is far from ideal because of the universal selector usage,
  158. // but is needed to fix https://github.com/twbs/bootstrap/issues/24800
  159. // stylelint-disable-next-line selector-max-universal
  160. > * {
  161. margin: $modal-footer-margin-between / 2;
  162. }
  163. }
  164. // Measure scrollbar width for padding body during modal show/hide
  165. .modal-scrollbar-measure {
  166. position: absolute;
  167. top: -9999px;
  168. width: 50px;
  169. height: 50px;
  170. overflow: scroll;
  171. }
  172. // Scale up the modal
  173. @include media-breakpoint-up(sm) {
  174. // Automatically set modal's width for larger viewports
  175. .modal-dialog {
  176. max-width: $modal-md;
  177. margin: $modal-dialog-margin-y-sm-up auto;
  178. }
  179. .modal-dialog-scrollable {
  180. max-height: subtract(100%, $modal-dialog-margin-y-sm-up * 2);
  181. .modal-content {
  182. max-height: subtract(100vh, $modal-dialog-margin-y-sm-up * 2);
  183. }
  184. }
  185. .modal-dialog-centered {
  186. min-height: subtract(100%, $modal-dialog-margin-y-sm-up * 2);
  187. &::before {
  188. height: subtract(100vh, $modal-dialog-margin-y-sm-up * 2);
  189. }
  190. }
  191. .modal-content {
  192. @include box-shadow($modal-content-box-shadow-sm-up);
  193. }
  194. .modal-sm { max-width: $modal-sm; }
  195. }
  196. @include media-breakpoint-up(lg) {
  197. .modal-lg,
  198. .modal-xl {
  199. max-width: $modal-lg;
  200. }
  201. }
  202. @include media-breakpoint-up(xl) {
  203. .modal-xl { max-width: $modal-xl; }
  204. }