_card.scss 6.22 KB
Newer Older
Mark Otto's avatar
cards  
Mark Otto committed
1
2
3
4
5
6
//
// Base styles
//

.card {
  position: relative;
Mark Otto's avatar
Mark Otto committed
7
8
  display: flex;
  flex-direction: column;
9
10
  min-width: 0;
  word-wrap: break-word;
11
  background-color: $card-bg;
12
  background-clip: border-box;
Mark Otto's avatar
Mark Otto committed
13
  border: $card-border-width solid $card-border-color;
14
  @include border-radius($card-border-radius);
15
16
17
18
19

  > hr {
    margin-right: 0;
    margin-left: 0;
  }
20
21
22
23
24
25
26
27
28
29
30
31

  > .list-group:first-child {
    .list-group-item:first-child {
      @include border-top-radius($card-border-radius);
    }
  }

  > .list-group:last-child {
    .list-group-item:last-child {
      @include border-bottom-radius($card-border-radius);
    }
  }
32
33
}

34
.card-body {
35
36
37
  // Enable `flex-grow: 1` for decks and groups so that card blocks take up
  // as much space as possible, ensuring footers are aligned to the bottom.
  flex: 1 1 auto;
38
  padding: $card-spacer-x;
Mark Otto's avatar
cards  
Mark Otto committed
39
}
40

Mark Otto's avatar
cards  
Mark Otto committed
41
.card-title {
42
  margin-bottom: $card-spacer-y;
Mark Otto's avatar
cards  
Mark Otto committed
43
}
44
45

.card-subtitle {
46
  margin-top: -$card-spacer-y / 2;
Mark Otto's avatar
cards  
Mark Otto committed
47
48
  margin-bottom: 0;
}
49
50
51

.card-text:last-child {
  margin-bottom: 0;
Mark Otto's avatar
cards  
Mark Otto committed
52
}
53

54
55
56
57
.card-link {
  @include hover {
    text-decoration: none;
  }
Mark Otto's avatar
cards  
Mark Otto committed
58

59
60
61
62
  + .card-link {
    margin-left: $card-spacer-x;
  }
}
Mark Otto's avatar
cards  
Mark Otto committed
63

Mark Otto's avatar
Mark Otto committed
64
//
65
// Optional textual caps
Mark Otto's avatar
Mark Otto committed
66
67
//

68
69
.card-header {
  padding: $card-spacer-y $card-spacer-x;
70
  margin-bottom: 0; // Removes the default margin-bottom of <hN>
71
  color: $card-cap-color;
72
  background-color: $card-cap-bg;
Mark Otto's avatar
Mark Otto committed
73
  border-bottom: $card-border-width solid $card-border-color;
Mark Otto's avatar
Mark Otto committed
74

75
  &:first-child {
76
    @include border-radius($card-inner-border-radius $card-inner-border-radius 0 0);
77
  }
78
79
80
81
82
83

  + .list-group {
    .list-group-item:first-child {
      border-top: 0;
    }
  }
Mark Otto's avatar
Mark Otto committed
84
85
}

86
87
.card-footer {
  padding: $card-spacer-y $card-spacer-x;
88
  background-color: $card-cap-bg;
Mark Otto's avatar
Mark Otto committed
89
  border-top: $card-border-width solid $card-border-color;
90
91

  &:last-child {
92
    @include border-radius(0 0 $card-inner-border-radius $card-inner-border-radius);
93
  }
Mark Otto's avatar
Mark Otto committed
94
95
96
}


97
98
99
100
101
//
// Header navs
//

.card-header-tabs {
102
  margin-right: -$card-spacer-x / 2;
103
  margin-bottom: -$card-spacer-y;
104
  margin-left: -$card-spacer-x / 2;
105
106
107
108
  border-bottom: 0;
}

.card-header-pills {
109
110
  margin-right: -$card-spacer-x / 2;
  margin-left: -$card-spacer-x / 2;
111
112
}

Mark Otto's avatar
cards  
Mark Otto committed
113
114
115
116
117
118
119
// Card image
.card-img-overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
120
  padding: $card-img-overlay-padding;
Mark Otto's avatar
cards  
Mark Otto committed
121
122
}

Mark Otto's avatar
Mark Otto committed
123
124
.card-img {
  width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch
125
  @include border-radius($card-inner-border-radius);
Mark Otto's avatar
Mark Otto committed
126
}
Mark Otto's avatar
cards  
Mark Otto committed
127
128
129

// Card image caps
.card-img-top {
Mark Otto's avatar
Mark Otto committed
130
  width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch
131
  @include border-top-radius($card-inner-border-radius);
Mark Otto's avatar
cards  
Mark Otto committed
132
}
Mark Otto's avatar
Mark Otto committed
133

Mark Otto's avatar
cards  
Mark Otto committed
134
.card-img-bottom {
Mark Otto's avatar
Mark Otto committed
135
  width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch
136
  @include border-bottom-radius($card-inner-border-radius);
Mark Otto's avatar
cards  
Mark Otto committed
137
138
139
}


140
// Card deck
Mark Otto's avatar
cards  
Mark Otto committed
141

142
143
144
145
146
147
148
149
150
.card-deck {
  display: flex;
  flex-direction: column;

  .card {
    margin-bottom: $card-deck-margin;
  }

  @include media-breakpoint-up(sm) {
151
    flex-flow: row wrap;
Mark Otto's avatar
Mark Otto committed
152
153
    margin-right: -$card-deck-margin;
    margin-left: -$card-deck-margin;
154
155

    .card {
156
      display: flex;
157
      // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4
158
      flex: 1 0 0%;
159
      flex-direction: column;
Mark Otto's avatar
Mark Otto committed
160
      margin-right: $card-deck-margin;
161
      margin-bottom: 0; // Override the default
Mark Otto's avatar
Mark Otto committed
162
      margin-left: $card-deck-margin;
163
164
165
    }
  }
}
Mark Otto's avatar
cards  
Mark Otto committed
166

167

Mark Otto's avatar
cards  
Mark Otto committed
168
169
170
171
//
// Card groups
//

172
173
174
175
.card-group {
  display: flex;
  flex-direction: column;

176
177
178
  // The child selector allows nested `.card` within `.card-group`
  // to display properly.
  > .card {
179
180
181
182
    margin-bottom: $card-group-margin;
  }

  @include media-breakpoint-up(sm) {
183
    flex-flow: row wrap;
184
185
186
    // The child selector allows nested `.card` within `.card-group`
    // to display properly.
    > .card {
187
      // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4
188
      flex: 1 0 0%;
189
      margin-bottom: 0;
190

191
192
193
      + .card {
        margin-left: 0;
        border-left: 0;
194
      }
195
196
197
198

      // Handle rounded corners
      @if $enable-rounded {
        &:first-child {
199
200
          @include border-right-radius(0);

201
202
          .card-img-top,
          .card-header {
203
            // stylelint-disable-next-line property-blacklist
204
205
            border-top-right-radius: 0;
          }
206
207
          .card-img-bottom,
          .card-footer {
208
            // stylelint-disable-next-line property-blacklist
209
210
            border-bottom-right-radius: 0;
          }
211
        }
212

213
        &:last-child {
214
          @include border-left-radius(0);
215

216
217
          .card-img-top,
          .card-header {
218
            // stylelint-disable-next-line property-blacklist
219
220
            border-top-left-radius: 0;
          }
221
222
          .card-img-bottom,
          .card-footer {
223
            // stylelint-disable-next-line property-blacklist
224
225
            border-bottom-left-radius: 0;
          }
226
        }
227

228
229
        &:only-child {
          @include border-radius($card-border-radius);
230

231
232
          .card-img-top,
          .card-header {
233
234
            @include border-top-radius($card-border-radius);
          }
235
236
          .card-img-bottom,
          .card-footer {
237
238
            @include border-bottom-radius($card-border-radius);
          }
239
240
        }

241
        &:not(:first-child):not(:last-child):not(:only-child) {
242
          @include border-radius(0);
243
244

          .card-img-top,
245
246
247
          .card-img-bottom,
          .card-header,
          .card-footer {
248
            @include border-radius(0);
249
          }
250
        }
251
252
      }
    }
Mark Otto's avatar
cards  
Mark Otto committed
253
254
255
256
257
  }
}


//
Mark Otto's avatar
Mark Otto committed
258
// Columns
Mark Otto's avatar
cards  
Mark Otto committed
259
260
//

Mark Otto's avatar
Mark Otto committed
261
262
263
264
265
266
.card-columns {
  .card {
    margin-bottom: $card-columns-margin;
  }

  @include media-breakpoint-up(sm) {
Mark Otto's avatar
Mark Otto committed
267
    column-count: $card-columns-count;
Mark Otto's avatar
Mark Otto committed
268
    column-gap: $card-columns-gap;
269
270
    orphans: 1;
    widows: 1;
Mark Otto's avatar
cards  
Mark Otto committed
271

272
    .card {
273
      display: inline-block; // Don't let them vertically span multiple columns
Mark Otto's avatar
Mark Otto committed
274
      width: 100%; // Don't let their width change
275
    }
Mark Otto's avatar
cards  
Mark Otto committed
276
277
  }
}
Andres Galante's avatar
Andres Galante committed
278
279
280
281
282
283
284


//
// Accordion
//

.accordion {
285
286
287
288
289
  .card {
    overflow: hidden;

    &:not(:first-of-type) {
      .card-header:first-child {
290
        @include border-radius(0);
291
      }
Andres Galante's avatar
Andres Galante committed
292

293
294
      &:not(:last-of-type) {
        border-bottom: 0;
295
        @include border-radius(0);
296
      }
Andres Galante's avatar
Andres Galante committed
297
298
    }

299
300
    &:first-of-type {
      border-bottom: 0;
301
      @include border-bottom-radius(0);
302
    }
Andres Galante's avatar
Andres Galante committed
303

304
    &:last-of-type {
305
      @include border-top-radius(0);
306
307
308
309
310
    }

    .card-header {
      margin-bottom: -$card-border-width;
    }
Andres Galante's avatar
Andres Galante committed
311
312
  }
}