_modal.scss 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. // Kill the scroll on the body
  6. .modal-open {
  7. overflow: hidden;
  8. }
  9. // Container that the modal scrolls within
  10. .modal {
  11. position: fixed;
  12. top: 0;
  13. right: 0;
  14. bottom: 0;
  15. left: 0;
  16. z-index: $zindex-modal;
  17. display: none;
  18. overflow: hidden;
  19. // Prevent Chrome on Windows from adding a focus outline. For details, see
  20. // https://github.com/twbs/bootstrap/pull/10951.
  21. outline: 0;
  22. // We deliberately don't use `-webkit-overflow-scrolling: touch;` due to a
  23. // gnarly iOS Safari bug: https://bugs.webkit.org/show_bug.cgi?id=158342
  24. // See also https://github.com/twbs/bootstrap/issues/17695
  25. .modal-open & {
  26. overflow-x: hidden;
  27. overflow-y: auto;
  28. }
  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: translate(0, -25%);
  41. }
  42. .modal.show & {
  43. transform: translate(0, 0);
  44. }
  45. }
  46. .modal-dialog-centered {
  47. display: flex;
  48. align-items: center;
  49. min-height: calc(100% - (#{$modal-dialog-margin} * 2));
  50. }
  51. // Actual modal
  52. .modal-content {
  53. position: relative;
  54. display: flex;
  55. flex-direction: column;
  56. width: 100%; // Ensure `.modal-content` extends the full width of the parent `.modal-dialog`
  57. // counteract the pointer-events: none; in the .modal-dialog
  58. pointer-events: auto;
  59. background-color: $modal-content-bg;
  60. background-clip: padding-box;
  61. border: $modal-content-border-width solid $modal-content-border-color;
  62. @include border-radius($modal-content-border-radius);
  63. @include box-shadow($modal-content-box-shadow-xs);
  64. // Remove focus outline from opened modal
  65. outline: 0;
  66. }
  67. // Modal background
  68. .modal-backdrop {
  69. position: fixed;
  70. top: 0;
  71. right: 0;
  72. bottom: 0;
  73. left: 0;
  74. z-index: $zindex-modal-backdrop;
  75. background-color: $modal-backdrop-bg;
  76. // Fade for backdrop
  77. &.fade { opacity: 0; }
  78. &.show { opacity: $modal-backdrop-opacity; }
  79. }
  80. // Modal header
  81. // Top section of the modal w/ title and dismiss
  82. .modal-header {
  83. display: flex;
  84. align-items: flex-start; // so the close btn always stays on the upper right corner
  85. justify-content: space-between; // Put modal header elements (title and dismiss) on opposite ends
  86. padding: $modal-header-padding;
  87. border-bottom: $modal-header-border-width solid $modal-header-border-color;
  88. @include border-top-radius($modal-content-border-radius);
  89. .close {
  90. padding: $modal-header-padding;
  91. // auto on the left force icon to the right even when there is no .modal-title
  92. margin: (-$modal-header-padding) (-$modal-header-padding) (-$modal-header-padding) auto;
  93. }
  94. }
  95. // Title text within header
  96. .modal-title {
  97. margin-bottom: 0;
  98. line-height: $modal-title-line-height;
  99. }
  100. // Modal body
  101. // Where all modal content resides (sibling of .modal-header and .modal-footer)
  102. .modal-body {
  103. position: relative;
  104. // Enable `flex-grow: 1` so that the body take up as much space as possible
  105. // when should there be a fixed height on `.modal-dialog`.
  106. flex: 1 1 auto;
  107. padding: $modal-inner-padding;
  108. }
  109. // Footer (for actions)
  110. .modal-footer {
  111. display: flex;
  112. align-items: center; // vertically center
  113. justify-content: flex-end; // Right align buttons with flex property because text-align doesn't work on flex items
  114. padding: $modal-inner-padding;
  115. border-top: $modal-footer-border-width solid $modal-footer-border-color;
  116. // Easily place margin between footer elements
  117. > :not(:first-child) { margin-left: .25rem; }
  118. > :not(:last-child) { margin-right: .25rem; }
  119. }
  120. // Measure scrollbar width for padding body during modal show/hide
  121. .modal-scrollbar-measure {
  122. position: absolute;
  123. top: -9999px;
  124. width: 50px;
  125. height: 50px;
  126. overflow: scroll;
  127. }
  128. // Scale up the modal
  129. @include media-breakpoint-up(sm) {
  130. // Automatically set modal's width for larger viewports
  131. .modal-dialog {
  132. max-width: $modal-md;
  133. margin: $modal-dialog-margin-y-sm-up auto;
  134. }
  135. .modal-dialog-centered {
  136. min-height: calc(100% - (#{$modal-dialog-margin-y-sm-up} * 2));
  137. }
  138. .modal-content {
  139. @include box-shadow($modal-content-box-shadow-sm-up);
  140. }
  141. .modal-sm { max-width: $modal-sm; }
  142. }
  143. @include media-breakpoint-up(lg) {
  144. .modal-lg { max-width: $modal-lg; }
  145. }