_card.scss 6.01 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
46

.card-subtitle {
  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
  background-color: $card-cap-bg;
Mark Otto's avatar
Mark Otto committed
72
  border-bottom: $card-border-width solid $card-border-color;
Mark Otto's avatar
Mark Otto committed
73

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

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

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

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


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// Header navs
//

.card-header-tabs {
  margin-right: -($card-spacer-x / 2);
  margin-bottom: -$card-spacer-y;
  margin-left: -($card-spacer-x / 2);
  border-bottom: 0;
}

.card-header-pills {
  margin-right: -($card-spacer-x / 2);
  margin-left: -($card-spacer-x / 2);
}

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

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

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

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


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

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

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

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

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

166

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

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

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

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

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

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

200
201
          .card-img-top,
          .card-header {
202
203
            border-top-right-radius: 0;
          }
204
205
          .card-img-bottom,
          .card-footer {
206
207
            border-bottom-right-radius: 0;
          }
208
        }
209

210
        &:last-child {
211
          @include border-left-radius(0);
212

213
214
          .card-img-top,
          .card-header {
215
216
            border-top-left-radius: 0;
          }
217
218
          .card-img-bottom,
          .card-footer {
219
220
            border-bottom-left-radius: 0;
          }
221
        }
222

223
224
        &:only-child {
          @include border-radius($card-border-radius);
225

226
227
          .card-img-top,
          .card-header {
228
229
            @include border-top-radius($card-border-radius);
          }
230
231
          .card-img-bottom,
          .card-footer {
232
233
            @include border-bottom-radius($card-border-radius);
          }
234
235
        }

236
        &:not(:first-child):not(:last-child):not(:only-child) {
237
          @include border-radius(0);
238
239

          .card-img-top,
240
241
242
          .card-img-bottom,
          .card-header,
          .card-footer {
243
            @include border-radius(0);
244
          }
245
        }
246
247
      }
    }
Mark Otto's avatar
cards  
Mark Otto committed
248
249
250
251
252
  }
}


//
Mark Otto's avatar
Mark Otto committed
253
// Columns
Mark Otto's avatar
cards  
Mark Otto committed
254
255
//

Mark Otto's avatar
Mark Otto committed
256
257
258
259
260
261
.card-columns {
  .card {
    margin-bottom: $card-columns-margin;
  }

  @include media-breakpoint-up(sm) {
Mark Otto's avatar
Mark Otto committed
262
    column-count: $card-columns-count;
Mark Otto's avatar
Mark Otto committed
263
    column-gap: $card-columns-gap;
264
265
    orphans: 1;
    widows: 1;
Mark Otto's avatar
cards  
Mark Otto committed
266

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


//
// Accordion
//

.accordion {
280
281
282
283
284
285
286
  .card {
    overflow: hidden;

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

288
289
290
291
      &:not(:last-of-type) {
        border-bottom: 0;
        border-radius: 0;
      }
Andres Galante's avatar
Andres Galante committed
292
293
    }

294
295
296
297
298
    &:first-of-type {
      border-bottom: 0;
      border-bottom-right-radius: 0;
      border-bottom-left-radius: 0;
    }
Andres Galante's avatar
Andres Galante committed
299

300
301
302
303
304
305
306
307
    &:last-of-type {
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }

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