_card.scss 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // Base styles
  3. //
  4. .card {
  5. position: relative;
  6. display: flex;
  7. flex-direction: column;
  8. min-width: 0; // See https://github.com/twbs/bootstrap/pull/22740#issuecomment-305868106
  9. word-wrap: break-word;
  10. background-color: $card-bg;
  11. background-clip: border-box;
  12. border: $card-border-width solid $card-border-color;
  13. @include border-radius($card-border-radius);
  14. > hr {
  15. margin-right: 0;
  16. margin-left: 0;
  17. }
  18. > .list-group:first-child {
  19. .list-group-item:first-child {
  20. @include border-top-radius($card-border-radius);
  21. }
  22. }
  23. > .list-group:last-child {
  24. .list-group-item:last-child {
  25. @include border-bottom-radius($card-border-radius);
  26. }
  27. }
  28. }
  29. .card-body {
  30. // Enable `flex-grow: 1` for decks and groups so that card blocks take up
  31. // as much space as possible, ensuring footers are aligned to the bottom.
  32. flex: 1 1 auto;
  33. padding: $card-spacer-x;
  34. color: $card-color;
  35. }
  36. .card-title {
  37. margin-bottom: $card-spacer-y;
  38. }
  39. .card-subtitle {
  40. margin-top: -$card-spacer-y / 2;
  41. margin-bottom: 0;
  42. }
  43. .card-text:last-child {
  44. margin-bottom: 0;
  45. }
  46. .card-link {
  47. @include hover {
  48. text-decoration: none;
  49. }
  50. + .card-link {
  51. margin-left: $card-spacer-x;
  52. }
  53. }
  54. //
  55. // Optional textual caps
  56. //
  57. .card-header {
  58. padding: $card-spacer-y $card-spacer-x;
  59. margin-bottom: 0; // Removes the default margin-bottom of <hN>
  60. color: $card-cap-color;
  61. background-color: $card-cap-bg;
  62. border-bottom: $card-border-width solid $card-border-color;
  63. &:first-child {
  64. @include border-radius($card-inner-border-radius $card-inner-border-radius 0 0);
  65. }
  66. + .list-group {
  67. .list-group-item:first-child {
  68. border-top: 0;
  69. }
  70. }
  71. }
  72. .card-footer {
  73. padding: $card-spacer-y $card-spacer-x;
  74. background-color: $card-cap-bg;
  75. border-top: $card-border-width solid $card-border-color;
  76. &:last-child {
  77. @include border-radius(0 0 $card-inner-border-radius $card-inner-border-radius);
  78. }
  79. }
  80. //
  81. // Header navs
  82. //
  83. .card-header-tabs {
  84. margin-right: -$card-spacer-x / 2;
  85. margin-bottom: -$card-spacer-y;
  86. margin-left: -$card-spacer-x / 2;
  87. border-bottom: 0;
  88. }
  89. .card-header-pills {
  90. margin-right: -$card-spacer-x / 2;
  91. margin-left: -$card-spacer-x / 2;
  92. }
  93. // Card image
  94. .card-img-overlay {
  95. position: absolute;
  96. top: 0;
  97. right: 0;
  98. bottom: 0;
  99. left: 0;
  100. padding: $card-img-overlay-padding;
  101. }
  102. .card-img {
  103. width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch
  104. @include border-radius($card-inner-border-radius);
  105. }
  106. // Card image caps
  107. .card-img-top {
  108. width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch
  109. @include border-top-radius($card-inner-border-radius);
  110. }
  111. .card-img-bottom {
  112. width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch
  113. @include border-bottom-radius($card-inner-border-radius);
  114. }
  115. // Card deck
  116. .card-deck {
  117. display: flex;
  118. flex-direction: column;
  119. .card {
  120. margin-bottom: $card-deck-margin;
  121. }
  122. @include media-breakpoint-up(sm) {
  123. flex-flow: row wrap;
  124. margin-right: -$card-deck-margin;
  125. margin-left: -$card-deck-margin;
  126. .card {
  127. display: flex;
  128. // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4
  129. flex: 1 0 0%;
  130. flex-direction: column;
  131. margin-right: $card-deck-margin;
  132. margin-bottom: 0; // Override the default
  133. margin-left: $card-deck-margin;
  134. }
  135. }
  136. }
  137. //
  138. // Card groups
  139. //
  140. .card-group {
  141. display: flex;
  142. flex-direction: column;
  143. // The child selector allows nested `.card` within `.card-group`
  144. // to display properly.
  145. > .card {
  146. margin-bottom: $card-group-margin;
  147. }
  148. @include media-breakpoint-up(sm) {
  149. flex-flow: row wrap;
  150. // The child selector allows nested `.card` within `.card-group`
  151. // to display properly.
  152. > .card {
  153. // Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4
  154. flex: 1 0 0%;
  155. margin-bottom: 0;
  156. + .card {
  157. margin-left: 0;
  158. border-left: 0;
  159. }
  160. // Handle rounded corners
  161. @if $enable-rounded {
  162. &:not(:last-child) {
  163. @include border-right-radius(0);
  164. .card-img-top,
  165. .card-header {
  166. // stylelint-disable-next-line property-blacklist
  167. border-top-right-radius: 0;
  168. }
  169. .card-img-bottom,
  170. .card-footer {
  171. // stylelint-disable-next-line property-blacklist
  172. border-bottom-right-radius: 0;
  173. }
  174. }
  175. &:not(:first-child) {
  176. @include border-left-radius(0);
  177. .card-img-top,
  178. .card-header {
  179. // stylelint-disable-next-line property-blacklist
  180. border-top-left-radius: 0;
  181. }
  182. .card-img-bottom,
  183. .card-footer {
  184. // stylelint-disable-next-line property-blacklist
  185. border-bottom-left-radius: 0;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. //
  193. // Columns
  194. //
  195. .card-columns {
  196. .card {
  197. margin-bottom: $card-columns-margin;
  198. }
  199. @include media-breakpoint-up(sm) {
  200. column-count: $card-columns-count;
  201. column-gap: $card-columns-gap;
  202. orphans: 1;
  203. widows: 1;
  204. .card {
  205. display: inline-block; // Don't let them vertically span multiple columns
  206. width: 100%; // Don't let their width change
  207. }
  208. }
  209. }
  210. //
  211. // Accordion
  212. //
  213. .accordion {
  214. > .card {
  215. overflow: hidden;
  216. &:not(:first-of-type) {
  217. .card-header:first-child {
  218. @include border-radius(0);
  219. }
  220. &:not(:last-of-type) {
  221. border-bottom: 0;
  222. @include border-radius(0);
  223. }
  224. }
  225. &:first-of-type {
  226. border-bottom: 0;
  227. @include border-bottom-radius(0);
  228. }
  229. &:last-of-type {
  230. @include border-top-radius(0);
  231. }
  232. .card-header {
  233. margin-bottom: -$card-border-width;
  234. }
  235. }
  236. }