_card.less 5.5 KB

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