Skip to content

Commit ddaf2f0

Browse files
committed
feat(card): align with 2018 material design spec
Aligns the card component with the latest Material Design spec. Also fixes an issue where the border radius wasn't being applied to the image inside the card.
1 parent 2b89342 commit ddaf2f0

File tree

2 files changed

+43
-59
lines changed

2 files changed

+43
-59
lines changed

src/lib/card/_card-theme.scss

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$foreground: map-get($theme, foreground);
1010

1111
.mat-card {
12-
@include _mat-theme-overridable-elevation(2, $theme);
12+
@include _mat-theme-overridable-elevation(1, $theme);
1313
background: mat-color($background, card);
1414
color: mat-color($foreground, text);
1515

@@ -32,13 +32,16 @@
3232
.mat-card-title {
3333
font: {
3434
size: mat-font-size($config, headline);
35-
weight: mat-font-weight($config, headline);
35+
weight: mat-font-weight($config, title);
3636
}
3737
}
3838

39-
.mat-card-subtitle,
40-
.mat-card-content,
4139
.mat-card-header .mat-card-title {
40+
font-size: mat-font-size($config, title);
41+
}
42+
43+
.mat-card-subtitle,
44+
.mat-card-content {
4245
font-size: mat-font-size($config, body-1);
4346
}
4447
}

src/lib/card/card.scss

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
@import '../../cdk/a11y/a11y';
44

55

6-
$mat-card-default-padding: 24px !default;
7-
$mat-card-mobile-padding: 24px 16px !default;
8-
$mat-card-border-radius: 2px !default;
6+
$mat-card-padding: 16px !default;
7+
$mat-card-border-radius: 4px !default;
98
$mat-card-header-size: 40px !default;
109

1110
.mat-card {
1211
@include mat-elevation-transition;
1312
display: block;
1413
position: relative;
15-
padding: $mat-card-default-padding;
14+
padding: $mat-card-padding;
1615
border-radius: $mat-card-border-radius;
1716

1817
.mat-divider-horizontal {
@@ -47,14 +46,19 @@ $mat-card-header-size: 40px !default;
4746
margin-bottom: 16px;
4847
}
4948

50-
.mat-card-title, .mat-card-subtitle, .mat-card-content {
49+
.mat-card-title {
50+
display: block;
51+
margin-bottom: 8px;
52+
}
53+
54+
.mat-card-subtitle, .mat-card-content {
5155
@extend %mat-card-section-base;
5256
}
5357

5458
.mat-card-actions {
5559
@extend %mat-card-section-base;
56-
margin-left: -16px;
57-
margin-right: -16px;
60+
margin-left: -$mat-card-padding / 2;
61+
margin-right: -$mat-card-padding / 2;
5862
padding: 8px 0;
5963
}
6064

@@ -64,22 +68,22 @@ $mat-card-header-size: 40px !default;
6468
}
6569

6670
.mat-card-image {
67-
width: calc(100% + 48px);
68-
margin: 0 -24px 16px -24px;
71+
width: calc(100% + #{$mat-card-padding * 2});
72+
margin: 0 (-$mat-card-padding) 16px (-$mat-card-padding);
6973
}
7074

7175
.mat-card-footer {
7276
// The negative margins pulls out the element, countering the padding
7377
// to get the footer to be flush against the side of the card.
74-
$margin: -$mat-card-default-padding;
78+
$margin: -$mat-card-padding;
7579

7680
display: block;
7781
margin: 0 $margin $margin $margin;
7882
}
7983

8084
.mat-card-actions {
8185
.mat-button, .mat-raised-button {
82-
margin: 0 4px;
86+
margin: 0 8px;
8387
}
8488
}
8589

@@ -88,10 +92,14 @@ $mat-card-header-size: 40px !default;
8892
.mat-card-header {
8993
display: flex;
9094
flex-direction: row;
95+
96+
.mat-card-title {
97+
margin-bottom: 12px;
98+
}
9199
}
92100

93101
.mat-card-header-text {
94-
margin: 0 8px;
102+
margin: 0 $mat-card-padding;
95103
}
96104

97105
.mat-card-avatar {
@@ -103,34 +111,22 @@ $mat-card-header-size: 40px !default;
103111

104112
// TITLE-GROUP STYLES
105113

106-
// images grouped with title in title-group layout
107-
%mat-card-title-img {
108-
// As per Material Design specifications, the images exceed the *top* content-box and take
109-
// up some space. The margin below is necessary because otherwise space of the actual card
110-
// content will be overlapped.
111-
margin: -8px 0 8px 0;
112-
}
113-
114114
.mat-card-title-group {
115115
display: flex;
116116
justify-content: space-between;
117-
margin: 0 -8px;
118117
}
119118

120119
.mat-card-sm-image {
121-
@extend %mat-card-title-img;
122120
width: 80px;
123121
height: 80px;
124122
}
125123

126124
.mat-card-md-image {
127-
@extend %mat-card-title-img;
128125
width: 112px;
129126
height: 112px;
130127
}
131128

132129
.mat-card-lg-image {
133-
@extend %mat-card-title-img;
134130
width: 152px;
135131
height: 152px;
136132
}
@@ -146,27 +142,16 @@ $mat-card-header-size: 40px !default;
146142
// Special treatment inside title group in order to fix the media areas inside of a title-group.
147143
// This can be removed once #12203 has been addressed.
148144
.mat-card-title-group > & {
149-
@extend %mat-card-title-img;
145+
// As per Material Design specifications, the images exceed the *top* content-box and take
146+
// up some space. The margin below is necessary because otherwise space of the actual card
147+
// content will be overlapped.
148+
margin: -8px 0 8px 0;
150149
}
151150
}
152151

153152
// MEDIA QUERIES
154153

155154
@media ($mat-xsmall) {
156-
.mat-card {
157-
padding: $mat-card-mobile-padding;
158-
}
159-
160-
.mat-card-actions {
161-
margin-left: -8px;
162-
margin-right: -8px;
163-
}
164-
165-
.mat-card-image {
166-
width: calc(100% + 32px);
167-
margin: 16px -16px;
168-
}
169-
170155
.mat-card-title-group {
171156
margin: 0;
172157
}
@@ -175,16 +160,6 @@ $mat-card-header-size: 40px !default;
175160
margin-left: 0;
176161
margin-right: 0;
177162
}
178-
179-
.mat-card-header {
180-
margin: -8px 0 0 0;
181-
}
182-
183-
.mat-card-footer {
184-
margin-left: -16px;
185-
margin-right: -16px;
186-
}
187-
188163
}
189164

190165
// FIRST/LAST CHILD ADJUSTMENTS
@@ -203,15 +178,17 @@ $mat-card-header-size: 40px !default;
203178
}
204179

205180
// if main image is on top, need to place it flush against top
206-
// (by stripping card's default 24px padding)
181+
// (by stripping card's default padding)
207182
.mat-card-image:first-child {
208-
margin-top: -24px;
183+
margin-top: -$mat-card-padding;
184+
border-top-left-radius: inherit;
185+
border-top-right-radius: inherit;
209186
}
210187

211188
// actions panel on bottom should be 8px from bottom of card
212-
// so must strip 16px from default card padding of 24px
189+
// so must strip 16px from default card padding
213190
.mat-card > .mat-card-actions:last-child {
214-
margin-bottom: -16px;
191+
margin-bottom: -8px;
215192
padding-bottom: 0;
216193
}
217194

@@ -223,6 +200,10 @@ $mat-card-header-size: 40px !default;
223200
margin-right: 0;
224201
}
225202

203+
.mat-card-title {
204+
margin-bottom: 8px;
205+
}
206+
226207
// should be 12px space between titles and subtitles generally
227208
// default margin-bottom is 16px, so need to move lower title up 4px
228209
.mat-card-title:not(:first-child), .mat-card-subtitle:not(:first-child) {
@@ -236,13 +217,13 @@ $mat-card-header-size: 40px !default;
236217
}
237218

238219
// xl image should always have 16px on top.
239-
// when it's the first el, it'll need to remove 8px from default card padding of 24px
220+
// when it's the first el, it'll need to remove 8px from default card padding
240221
.mat-card > .mat-card-xl-image:first-child {
241222
margin-top: -8px;
242223
}
243224

244225
// xl image should always have 16px on bottom
245-
// when it's the last el, it'll need to remove 8px from default card padding of 24px
226+
// when it's the last el, it'll need to remove 8px from default card padding
246227
.mat-card > .mat-card-xl-image:last-child {
247228
margin-bottom: -8px;
248229
}

0 commit comments

Comments
 (0)