Skip to content

Commit 484dc8b

Browse files
crisbetommalerba
authored andcommitted
feat(card): align with 2018 material design spec (#12731)
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. ![material-cb7ec firebaseapp com_card](https://user-images.githubusercontent.com/4450522/44302072-8d525980-a322-11e8-9976-f085a0573302.png) ![localhost_4200_card](https://user-images.githubusercontent.com/4450522/44302076-904d4a00-a322-11e8-9da3-ff07e2ee2259.png)
1 parent 5d34cb7 commit 484dc8b

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 {
@@ -107,34 +115,22 @@ $mat-card-header-size: 40px !default;
107115

108116
// TITLE-GROUP STYLES
109117

110-
// images grouped with title in title-group layout
111-
%mat-card-title-img {
112-
// As per Material Design specifications, the images exceed the *top* content-box and take
113-
// up some space. The margin below is necessary because otherwise space of the actual card
114-
// content will be overlapped.
115-
margin: -8px 0 8px 0;
116-
}
117-
118118
.mat-card-title-group {
119119
display: flex;
120120
justify-content: space-between;
121-
margin: 0 -8px;
122121
}
123122

124123
.mat-card-sm-image {
125-
@extend %mat-card-title-img;
126124
width: 80px;
127125
height: 80px;
128126
}
129127

130128
.mat-card-md-image {
131-
@extend %mat-card-title-img;
132129
width: 112px;
133130
height: 112px;
134131
}
135132

136133
.mat-card-lg-image {
137-
@extend %mat-card-title-img;
138134
width: 152px;
139135
height: 152px;
140136
}
@@ -150,27 +146,16 @@ $mat-card-header-size: 40px !default;
150146
// Special treatment inside title group in order to fix the media areas inside of a title-group.
151147
// This can be removed once #12203 has been addressed.
152148
.mat-card-title-group > & {
153-
@extend %mat-card-title-img;
149+
// As per Material Design specifications, the images exceed the *top* content-box and take
150+
// up some space. The margin below is necessary because otherwise space of the actual card
151+
// content will be overlapped.
152+
margin: -8px 0 8px 0;
154153
}
155154
}
156155

157156
// MEDIA QUERIES
158157

159158
@media ($mat-xsmall) {
160-
.mat-card {
161-
padding: $mat-card-mobile-padding;
162-
}
163-
164-
.mat-card-actions {
165-
margin-left: -8px;
166-
margin-right: -8px;
167-
}
168-
169-
.mat-card-image {
170-
width: calc(100% + 32px);
171-
margin: 16px -16px;
172-
}
173-
174159
.mat-card-title-group {
175160
margin: 0;
176161
}
@@ -179,16 +164,6 @@ $mat-card-header-size: 40px !default;
179164
margin-left: 0;
180165
margin-right: 0;
181166
}
182-
183-
.mat-card-header {
184-
margin: -8px 0 0 0;
185-
}
186-
187-
.mat-card-footer {
188-
margin-left: -16px;
189-
margin-right: -16px;
190-
}
191-
192167
}
193168

194169
// FIRST/LAST CHILD ADJUSTMENTS
@@ -207,15 +182,17 @@ $mat-card-header-size: 40px !default;
207182
}
208183

209184
// if main image is on top, need to place it flush against top
210-
// (by stripping card's default 24px padding)
185+
// (by stripping card's default padding)
211186
.mat-card-image:first-child {
212-
margin-top: -24px;
187+
margin-top: -$mat-card-padding;
188+
border-top-left-radius: inherit;
189+
border-top-right-radius: inherit;
213190
}
214191

215192
// actions panel on bottom should be 8px from bottom of card
216-
// so must strip 16px from default card padding of 24px
193+
// so must strip 16px from default card padding
217194
.mat-card > .mat-card-actions:last-child {
218-
margin-bottom: -16px;
195+
margin-bottom: -8px;
219196
padding-bottom: 0;
220197
}
221198

@@ -227,6 +204,10 @@ $mat-card-header-size: 40px !default;
227204
margin-right: 0;
228205
}
229206

207+
.mat-card-title {
208+
margin-bottom: 8px;
209+
}
210+
230211
// should be 12px space between titles and subtitles generally
231212
// default margin-bottom is 16px, so need to move lower title up 4px
232213
.mat-card-title:not(:first-child), .mat-card-subtitle:not(:first-child) {
@@ -240,13 +221,13 @@ $mat-card-header-size: 40px !default;
240221
}
241222

242223
// xl image should always have 16px on top.
243-
// when it's the first el, it'll need to remove 8px from default card padding of 24px
224+
// when it's the first el, it'll need to remove 8px from default card padding
244225
.mat-card > .mat-card-xl-image:first-child {
245226
margin-top: -8px;
246227
}
247228

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

0 commit comments

Comments
 (0)