_modal.scss 4.51 KB
Newer Older
1
2
3
// .modal-open      - body class for killing the scroll
// .modal           - container to scroll within
// .modal-dialog    - positioning shell for the actual modal
4
// .modal-content   - actual modal w/ bg and corners and stuff
5

6

7
8
9
10
11
12
13
// Kill the scroll on the body
.modal-open {
  overflow: hidden;
}

// Container that the modal scrolls within
.modal {
14
15
16
17
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
18
  left: 0;
Mark Otto's avatar
Mark Otto committed
19
  z-index: $zindex-modal;
20
21
  display: none;
  overflow: hidden;
22
23
  // Prevent Chrome on Windows from adding a focus outline. For details, see
  // https://github.com/twbs/bootstrap/pull/10951.
Martynas's avatar
Martynas committed
24
  outline: 0;
25
26
27
  // We deliberately don't use `-webkit-overflow-scrolling: touch;` due to a
  // gnarly iOS Safari bug: https://bugs.webkit.org/show_bug.cgi?id=158342
  // See also https://github.com/twbs/bootstrap/issues/17695
Mark Otto's avatar
Mark Otto committed
28

29
30
31
  .modal-open & {
    overflow-x: hidden;
    overflow-y: auto;
Mark Otto's avatar
Mark Otto committed
32
  }
33
}
34

35
36
// Shell div to position the modal with bottom padding
.modal-dialog {
37
  position: relative;
38
  width: auto;
39
  margin: $modal-dialog-margin;
40
41
  // allow clicks to pass through for custom click handling to close modal
  pointer-events: none;
42
43
44
45
46
47
48
49
50

  // When fading in the modal, animate it to slide down
  .modal.fade & {
    @include transition($modal-transition);
    transform: translate(0, -25%);
  }
  .modal.show & {
    transform: translate(0, 0);
  }
51
52
}

53
54
55
.modal-dialog-centered {
  display: flex;
  align-items: center;
56
  min-height: calc(100% - (#{$modal-dialog-margin} * 2));
57
58
}

59
60
61
// Actual modal
.modal-content {
  position: relative;
62
63
  display: flex;
  flex-direction: column;
64
  width: 100%; // Ensure `.modal-content` extends the full width of the parent `.modal-dialog`
65
66
  // counteract the pointer-events: none; in the .modal-dialog
  pointer-events: auto;
Mark Otto's avatar
Mark Otto committed
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($border-radius-lg);
71
  @include box-shadow($modal-content-box-shadow-xs);
Mark Otto's avatar
Mark Otto committed
72
  // Remove focus outline from opened modal
73
  outline: 0;
74
}
75
76
77

// Modal background
.modal-backdrop {
78
  position: fixed;
79
80
  top: 0;
  right: 0;
81
  bottom: 0;
82
  left: 0;
83
  z-index: $zindex-modal-backdrop;
Mark Otto's avatar
Mark Otto committed
84
  background-color: $modal-backdrop-bg;
Mark Otto's avatar
Mark Otto committed
85

86
  // Fade for backdrop
87
  &.fade { opacity: 0; }
Starsam80's avatar
Starsam80 committed
88
  &.show { opacity: $modal-backdrop-opacity; }
89
90
91
92
}

// Modal header
// Top section of the modal w/ title and dismiss
93
.modal-header {
94
  display: flex;
95
  align-items: flex-start; // so the close btn always stays on the upper right corner
Mark Otto's avatar
linting    
Mark Otto committed
96
  justify-content: space-between; // Put modal header elements (title and dismiss) on opposite ends
97
  padding: $modal-header-padding;
98
  border-bottom: $modal-header-border-width solid $modal-header-border-color;
99
  @include border-top-radius($border-radius-lg);
100
101

  .close {
102
    padding: $modal-header-padding;
XhmikosR's avatar
XhmikosR committed
103
104
    // auto on the left force icon to the right even when there is no .modal-title
    margin: (-$modal-header-padding) (-$modal-header-padding) (-$modal-header-padding) auto;
105
  }
106
107
108
109
}

// Title text within header
.modal-title {
110
  margin-bottom: 0;
Mark Otto's avatar
Mark Otto committed
111
  line-height: $modal-title-line-height;
112
}
113

114
115
// Modal body
// Where all modal content resides (sibling of .modal-header and .modal-footer)
116
.modal-body {
117
  position: relative;
118
119
120
  // Enable `flex-grow: 1` so that the body take up as much space as possible
  // when should there be a fixed height on `.modal-dialog`.
  flex: 1 1 auto;
Mark Otto's avatar
Mark Otto committed
121
  padding: $modal-inner-padding;
122
}
123
124

// Footer (for actions)
125
.modal-footer {
126
127
  display: flex;
  align-items: center; // vertically center
Mark Otto's avatar
linting    
Mark Otto committed
128
  justify-content: flex-end; // Right align buttons with flex property because text-align doesn't work on flex items
Mark Otto's avatar
Mark Otto committed
129
  padding: $modal-inner-padding;
130
  border-top: $modal-footer-border-width solid $modal-footer-border-color;
131
132
133
134

  // Easily place margin between footer elements
  > :not(:first-child) { margin-left: .25rem; }
  > :not(:last-child) { margin-right: .25rem; }
135
}
136

fat's avatar
fat committed
137
138
139
140
141
142
143
144
145
// Measure scrollbar width for padding body during modal show/hide
.modal-scrollbar-measure {
  position: absolute;
  top: -9999px;
  width: 50px;
  height: 50px;
  overflow: scroll;
}

Mark Otto's avatar
Mark Otto committed
146
// Scale up the modal
147
@include media-breakpoint-up(sm) {
148
  // Automatically set modal's width for larger viewports
149
  .modal-dialog {
Mark Otto's avatar
Mark Otto committed
150
    max-width: $modal-md;
151
    margin: $modal-dialog-margin-y-sm-up auto;
152
  }
Mark Otto's avatar
Mark Otto committed
153

154
  .modal-dialog-centered {
155
    min-height: calc(100% - (#{$modal-dialog-margin-y-sm-up} * 2));
156
157
  }

Mark Otto's avatar
Mark Otto committed
158
  .modal-content {
159
    @include box-shadow($modal-content-box-shadow-sm-up);
Mark Otto's avatar
Mark Otto committed
160
  }
161

Mark Otto's avatar
Mark Otto committed
162
  .modal-sm { max-width: $modal-sm; }
163

164
}
165

Mark Otto's avatar
Mark Otto committed
166
167
@include media-breakpoint-up(lg) {
  .modal-lg { max-width: $modal-lg; }
168
}