_modal.scss 5.7 KB

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