_modal.scss 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. height: min-content; // Reset height to 0 except on IE
  74. content: "";
  75. }
  76. // Ensure `.modal-body` shows scrollbar (IE10/11)
  77. &.modal-dialog-scrollable {
  78. flex-direction: column;
  79. justify-content: center;
  80. height: 100%;
  81. .modal-content {
  82. max-height: none;
  83. }
  84. &::before {
  85. content: none;
  86. }
  87. }
  88. }
  89. // Actual modal
  90. .modal-content {
  91. position: relative;
  92. display: flex;
  93. flex-direction: column;
  94. width: 100%; // Ensure `.modal-content` extends the full width of the parent `.modal-dialog`
  95. // counteract the pointer-events: none; in the .modal-dialog
  96. color: $modal-content-color;
  97. pointer-events: auto;
  98. background-color: $modal-content-bg;
  99. background-clip: padding-box;
  100. border: $modal-content-border-width solid $modal-content-border-color;
  101. @include border-radius($modal-content-border-radius);
  102. @include box-shadow($modal-content-box-shadow-xs);
  103. // Remove focus outline from opened modal
  104. outline: 0;
  105. }
  106. // Modal background
  107. .modal-backdrop {
  108. position: fixed;
  109. top: 0;
  110. left: 0;
  111. z-index: $zindex-modal-backdrop;
  112. width: 100vw;
  113. height: 100vh;
  114. background-color: $modal-backdrop-bg;
  115. // Fade for backdrop
  116. &.fade { opacity: 0; }
  117. &.show { opacity: $modal-backdrop-opacity; }
  118. }
  119. // Modal header
  120. // Top section of the modal w/ title and dismiss
  121. .modal-header {
  122. display: flex;
  123. align-items: flex-start; // so the close btn always stays on the upper right corner
  124. justify-content: space-between; // Put modal header elements (title and dismiss) on opposite ends
  125. padding: $modal-header-padding;
  126. border-bottom: $modal-header-border-width solid $modal-header-border-color;
  127. @include border-top-radius($modal-content-inner-border-radius);
  128. .close {
  129. padding: $modal-header-padding;
  130. // auto on the left force icon to the right even when there is no .modal-title
  131. margin: (-$modal-header-padding-y) (-$modal-header-padding-x) (-$modal-header-padding-y) auto;
  132. }
  133. }
  134. // Title text within header
  135. .modal-title {
  136. margin-bottom: 0;
  137. line-height: $modal-title-line-height;
  138. }
  139. // Modal body
  140. // Where all modal content resides (sibling of .modal-header and .modal-footer)
  141. .modal-body {
  142. position: relative;
  143. // Enable `flex-grow: 1` so that the body take up as much space as possible
  144. // when there should be a fixed height on `.modal-dialog`.
  145. flex: 1 1 auto;
  146. padding: $modal-inner-padding;
  147. }
  148. // Footer (for actions)
  149. .modal-footer {
  150. display: flex;
  151. flex-wrap: wrap;
  152. align-items: center; // vertically center
  153. justify-content: flex-end; // Right align buttons with flex property because text-align doesn't work on flex items
  154. padding: $modal-inner-padding - $modal-footer-margin-between / 2;
  155. border-top: $modal-footer-border-width solid $modal-footer-border-color;
  156. @include border-bottom-radius($modal-content-inner-border-radius);
  157. // Place margin between footer elements
  158. // This solution is far from ideal because of the universal selector usage,
  159. // but is needed to fix https://github.com/twbs/bootstrap/issues/24800
  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. height: min-content;
  190. }
  191. }
  192. .modal-content {
  193. @include box-shadow($modal-content-box-shadow-sm-up);
  194. }
  195. .modal-sm { max-width: $modal-sm; }
  196. }
  197. @include media-breakpoint-up(lg) {
  198. .modal-lg,
  199. .modal-xl {
  200. max-width: $modal-lg;
  201. }
  202. }
  203. @include media-breakpoint-up(xl) {
  204. .modal-xl { max-width: $modal-xl; }
  205. }