0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-22 19:54:22 +01:00
Bootstrap/scss/_card.scss

245 lines
7.9 KiB
SCSS
Raw Normal View History

2024-07-29 22:04:11 -07:00
@use "mixins/border-radius";
@use "mixins/box-shadow";
@use "mixins/breakpoints";
@use "variables";
2014-08-05 17:12:24 -07:00
//
// Base styles
//
.card {
// scss-docs-start card-css-vars
2024-07-29 22:04:11 -07:00
--#{variables.$prefix}card-spacer-y: #{variables.$card-spacer-y};
--#{variables.$prefix}card-spacer-x: #{variables.$card-spacer-x};
--#{variables.$prefix}card-title-spacer-y: #{variables.$card-title-spacer-y};
--#{variables.$prefix}card-title-color: #{variables.$card-title-color};
--#{variables.$prefix}card-subtitle-color: #{variables.$card-subtitle-color};
--#{variables.$prefix}card-border-width: #{variables.$card-border-width};
--#{variables.$prefix}card-border-color: #{variables.$card-border-color};
--#{variables.$prefix}card-border-radius: #{variables.$card-border-radius};
--#{variables.$prefix}card-box-shadow: #{variables.$card-box-shadow};
--#{variables.$prefix}card-inner-border-radius: #{variables.$card-inner-border-radius};
--#{variables.$prefix}card-cap-padding-y: #{variables.$card-cap-padding-y};
--#{variables.$prefix}card-cap-padding-x: #{variables.$card-cap-padding-x};
--#{variables.$prefix}card-cap-bg: #{variables.$card-cap-bg};
--#{variables.$prefix}card-cap-color: #{variables.$card-cap-color};
--#{variables.$prefix}card-height: #{variables.$card-height};
--#{variables.$prefix}card-color: #{variables.$card-color};
--#{variables.$prefix}card-bg: #{variables.$card-bg};
--#{variables.$prefix}card-img-overlay-padding: #{variables.$card-img-overlay-padding};
--#{variables.$prefix}card-group-margin: #{variables.$card-group-margin};
// scss-docs-end card-css-vars
2014-08-05 17:12:24 -07:00
position: relative;
display: flex;
flex-direction: column;
min-width: 0; // See https://github.com/twbs/bootstrap/pull/22740#issuecomment-305868106
2024-07-29 22:04:11 -07:00
height: var(--#{variables.$prefix}card-height);
color: var(--#{variables.$prefix}body-color);
word-wrap: break-word;
2024-07-29 22:04:11 -07:00
background-color: var(--#{variables.$prefix}card-bg);
2017-06-30 15:28:50 -07:00
background-clip: border-box;
2024-07-29 22:04:11 -07:00
border: var(--#{variables.$prefix}card-border-width) solid var(--#{variables.$prefix}card-border-color);
@include border-radius.border-radius(var(--#{variables.$prefix}card-border-radius));
@include box-shadow.box-shadow(var(--#{variables.$prefix}card-box-shadow));
> hr {
margin-right: 0;
margin-left: 0;
}
> .list-group {
border-top: inherit;
border-bottom: inherit;
&:first-child {
border-top-width: 0;
2024-07-29 22:04:11 -07:00
@include border-radius.border-top-radius(var(--#{variables.$prefix}card-inner-border-radius));
}
&:last-child {
border-bottom-width: 0;
2024-07-29 22:04:11 -07:00
@include border-radius.border-bottom-radius(var(--#{variables.$prefix}card-inner-border-radius));
}
}
// Due to specificity of the above selector (`.card > .list-group`), we must
// use a child selector here to prevent double borders.
> .card-header + .list-group,
> .list-group + .card-footer {
border-top: 0;
}
2015-05-28 14:07:34 -07:00
}
.card-body {
// 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;
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}card-spacer-y) var(--#{variables.$prefix}card-spacer-x);
color: var(--#{variables.$prefix}card-color);
2014-08-05 17:12:24 -07:00
}
2015-05-28 14:07:34 -07:00
2014-08-05 17:12:24 -07:00
.card-title {
2024-07-29 22:04:11 -07:00
margin-bottom: var(--#{variables.$prefix}card-title-spacer-y);
color: var(--#{variables.$prefix}card-title-color);
2014-08-05 17:12:24 -07:00
}
2015-05-28 14:07:34 -07:00
.card-subtitle {
2024-07-29 22:04:11 -07:00
margin-top: calc(-.5 * var(--#{variables.$prefix}card-title-spacer-y)); // stylelint-disable-line function-disallowed-list
2014-08-05 17:12:24 -07:00
margin-bottom: 0;
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}card-subtitle-color);
2014-08-05 17:12:24 -07:00
}
2015-05-28 14:07:34 -07:00
.card-text:last-child {
margin-bottom: 0;
2014-08-05 17:12:24 -07:00
}
2015-05-28 14:07:34 -07:00
.card-link {
&:hover {
2024-07-29 22:04:11 -07:00
text-decoration: if(variables.$link-hover-decoration == underline, none, null);
}
2014-08-05 17:12:24 -07:00
2015-05-28 14:07:34 -07:00
+ .card-link {
2024-07-29 22:04:11 -07:00
margin-left: var(--#{variables.$prefix}card-spacer-x);
2015-05-28 14:07:34 -07:00
}
}
2014-08-05 17:12:24 -07:00
2015-05-27 19:00:11 -07:00
//
2015-05-28 14:07:34 -07:00
// Optional textual caps
2015-05-27 19:00:11 -07:00
//
2015-05-28 14:07:34 -07:00
.card-header {
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}card-cap-padding-y) var(--#{variables.$prefix}card-cap-padding-x);
margin-bottom: 0; // Removes the default margin-bottom of <hN>
2024-07-29 22:04:11 -07:00
color: var(--#{variables.$prefix}card-cap-color);
background-color: var(--#{variables.$prefix}card-cap-bg);
border-bottom: var(--#{variables.$prefix}card-border-width) solid var(--#{variables.$prefix}card-border-color);
2015-05-27 19:00:11 -07:00
2015-05-28 14:07:34 -07:00
&:first-child {
2024-07-29 22:04:11 -07:00
@include border-radius.border-radius(var(--#{variables.$prefix}card-inner-border-radius) var(--#{variables.$prefix}card-inner-border-radius) 0 0);
2015-05-28 14:07:34 -07:00
}
2015-05-27 19:00:11 -07:00
}
2015-05-28 14:07:34 -07:00
.card-footer {
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}card-cap-padding-y) var(--#{variables.$prefix}card-cap-padding-x);
color: var(--#{variables.$prefix}card-cap-color);
background-color: var(--#{variables.$prefix}card-cap-bg);
border-top: var(--#{variables.$prefix}card-border-width) solid var(--#{variables.$prefix}card-border-color);
2015-05-28 14:07:34 -07:00
&:last-child {
2024-07-29 22:04:11 -07:00
@include border-radius.border-radius(0 0 var(--#{variables.$prefix}card-inner-border-radius) var(--#{variables.$prefix}card-inner-border-radius));
2015-05-28 14:07:34 -07:00
}
2015-05-27 19:00:11 -07:00
}
2016-01-17 18:55:24 -08:00
//
// Header navs
//
.card-header-tabs {
2024-07-29 22:04:11 -07:00
margin-right: calc(-.5 * var(--#{variables.$prefix}card-cap-padding-x)); // stylelint-disable-line function-disallowed-list
margin-bottom: calc(-1 * var(--#{variables.$prefix}card-cap-padding-y)); // stylelint-disable-line function-disallowed-list
margin-left: calc(-.5 * var(--#{variables.$prefix}card-cap-padding-x)); // stylelint-disable-line function-disallowed-list
2016-01-17 18:55:24 -08:00
border-bottom: 0;
.nav-link.active {
2024-07-29 22:04:11 -07:00
background-color: var(--#{variables.$prefix}card-bg);
border-bottom-color: var(--#{variables.$prefix}card-bg);
}
2016-01-17 18:55:24 -08:00
}
.card-header-pills {
2024-07-29 22:04:11 -07:00
margin-right: calc(-.5 * var(--#{variables.$prefix}card-cap-padding-x)); // stylelint-disable-line function-disallowed-list
margin-left: calc(-.5 * var(--#{variables.$prefix}card-cap-padding-x)); // stylelint-disable-line function-disallowed-list
2016-01-17 18:55:24 -08:00
}
2014-08-05 17:12:24 -07:00
// Card image
.card-img-overlay {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
2024-07-29 22:04:11 -07:00
padding: var(--#{variables.$prefix}card-img-overlay-padding);
@include border-radius.border-radius(var(--#{variables.$prefix}card-inner-border-radius));
2014-08-05 17:12:24 -07:00
}
2019-09-12 23:30:47 +09:00
.card-img,
.card-img-top,
.card-img-bottom {
width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch
}
2014-08-05 17:12:24 -07:00
2019-09-12 23:30:47 +09:00
.card-img,
2014-08-05 17:12:24 -07:00
.card-img-top {
2024-07-29 22:04:11 -07:00
@include border-radius.border-top-radius(var(--#{variables.$prefix}card-inner-border-radius));
2014-08-05 17:12:24 -07:00
}
2019-09-12 23:30:47 +09:00
.card-img,
2014-08-05 17:12:24 -07:00
.card-img-bottom {
2024-07-29 22:04:11 -07:00
@include border-radius.border-bottom-radius(var(--#{variables.$prefix}card-inner-border-radius));
2014-08-05 17:12:24 -07:00
}
//
// Card groups
//
.card-group {
// The child selector allows nested `.card` within `.card-group`
// to display properly.
> .card {
2024-07-29 22:04:11 -07:00
margin-bottom: var(--#{variables.$prefix}card-group-margin);
}
2024-07-29 22:04:11 -07:00
@include breakpoints.media-breakpoint-up(sm) {
2019-04-25 21:10:55 +02:00
display: flex;
2016-12-21 20:26:17 -08:00
flex-flow: row wrap;
// The child selector allows nested `.card` within `.card-group`
// to display properly.
> .card {
// Flexbugs #4: https://github.com/philipwalton/flexbugs#flexbug-4
flex: 1 0 0%;
margin-bottom: 0;
2015-05-28 14:07:34 -07:00
+ .card {
margin-left: 0;
border-left: 0;
2015-05-28 14:07:34 -07:00
}
// Handle rounded corners
2024-07-29 22:04:11 -07:00
@if variables.$enable-rounded {
2018-12-23 08:19:07 +01:00
&:not(:last-child) {
2024-07-29 22:04:11 -07:00
@include border-radius.border-end-radius(0);
2015-11-12 22:02:35 -08:00
2017-10-22 21:18:03 +02:00
.card-img-top,
.card-header {
2020-09-28 14:57:48 +03:00
// stylelint-disable-next-line property-disallowed-list
border-top-right-radius: 0;
}
2017-10-22 21:18:03 +02:00
.card-img-bottom,
.card-footer {
2020-09-28 14:57:48 +03:00
// stylelint-disable-next-line property-disallowed-list
border-bottom-right-radius: 0;
}
2015-05-28 14:07:34 -07:00
}
2018-12-23 08:19:07 +01:00
&:not(:first-child) {
2024-07-29 22:04:11 -07:00
@include border-radius.border-start-radius(0);
2017-10-22 21:18:03 +02:00
.card-img-top,
.card-header {
2020-09-28 14:57:48 +03:00
// stylelint-disable-next-line property-disallowed-list
border-top-left-radius: 0;
}
2017-10-22 21:18:03 +02:00
.card-img-bottom,
.card-footer {
2020-09-28 14:57:48 +03:00
// stylelint-disable-next-line property-disallowed-list
border-bottom-left-radius: 0;
}
2015-05-28 14:07:34 -07:00
}
}
}
2014-08-05 17:12:24 -07:00
}
}