Skip to content

Commit c440f84

Browse files
authored
fix(material/card): don't add extra padding around mat-card-title-group (#25292)
* fix(material/card): don't add extra padding around mat-card-title-group The card demo page forgot to include mat-card-header which caused many of the cards to look strange. At some point it looks like padding was added to mat-card-title-group to compensate in some cases. This PR removes that padding and adds the missing mat-card-header blocks instead. * fixup! fix(material/card): don't add extra padding around mat-card-title-group
1 parent 2905638 commit c440f84

File tree

2 files changed

+53
-38
lines changed

2 files changed

+53
-38
lines changed

src/dev-app/mdc-card/mdc-card-demo.html

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
</mat-card>
1414

1515
<mat-card [appearance]="appearance">
16-
<mat-card-subtitle>Subtitle</mat-card-subtitle>
17-
<mat-card-title>Card with title and footer</mat-card-title>
16+
<mat-card-header>
17+
<mat-card-subtitle>Subtitle</mat-card-subtitle>
18+
<mat-card-title>Card with title and footer</mat-card-title>
19+
</mat-card-header>
1820
<mat-card-content>
1921
<p>This is supporting text.</p>
2022
<p>{{longText}}</p>
@@ -26,8 +28,10 @@
2628
</mat-card>
2729

2830
<mat-card [appearance]="appearance">
29-
<mat-card-subtitle>Subtitle</mat-card-subtitle>
30-
<mat-card-title>Card with title, footer, and inset-divider</mat-card-title>
31+
<mat-card-header>
32+
<mat-card-subtitle>Subtitle</mat-card-subtitle>
33+
<mat-card-title>Card with title, footer, and inset-divider</mat-card-title>
34+
</mat-card-header>
3135
<mat-card-content>
3236
<p>This is supporting text.</p>
3337
<p>{{longText}}</p>
@@ -41,7 +45,9 @@
4145

4246
<mat-card [appearance]="appearance">
4347
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
44-
<mat-card-title>Content Title</mat-card-title>
48+
<mat-card-header>
49+
<mat-card-title>Content Title</mat-card-title>
50+
</mat-card-header>
4551
<mat-card-content>
4652
<p>Here is some content</p>
4753
</mat-card-content>
@@ -64,7 +70,9 @@
6470
</mat-card>
6571

6672
<mat-card class="demo-card-blue mat-card-flat" [appearance]="appearance">
67-
<mat-card-title>Easily customizable</mat-card-title>
73+
<mat-card-header>
74+
<mat-card-title>Easily customizable</mat-card-title>
75+
</mat-card-header>
6876
<mat-card-actions>
6977
<button mat-button>First</button>
7078
<button mat-button>Second</button>
@@ -75,44 +83,52 @@
7583
<h2>Cards with media area</h2>
7684

7785
<mat-card [appearance]="appearance">
78-
<mat-card-title-group>
79-
<mat-card-title>Card</mat-card-title>
80-
<mat-card-subtitle>Small</mat-card-subtitle>
81-
<img mat-card-sm-image>
82-
</mat-card-title-group>
86+
<mat-card-header>
87+
<mat-card-title-group>
88+
<mat-card-title>Card</mat-card-title>
89+
<mat-card-subtitle>Small</mat-card-subtitle>
90+
<img mat-card-sm-image>
91+
</mat-card-title-group>
92+
</mat-card-header>
8393
<mat-card-content>
8494
{{longText}}
8595
</mat-card-content>
8696
</mat-card>
8797

8898
<mat-card [appearance]="appearance">
89-
<mat-card-title-group>
90-
<mat-card-title>Card</mat-card-title>
91-
<mat-card-subtitle>Medium</mat-card-subtitle>
92-
<img mat-card-md-image>
93-
</mat-card-title-group>
99+
<mat-card-header>
100+
<mat-card-title-group>
101+
<mat-card-title>Card</mat-card-title>
102+
<mat-card-subtitle>Medium</mat-card-subtitle>
103+
<img mat-card-md-image>
104+
</mat-card-title-group>
105+
</mat-card-header>
94106
<mat-card-content>
95107
{{longText}}
96108
</mat-card-content>
97109
</mat-card>
98110

99111
<mat-card [appearance]="appearance">
100-
<mat-card-title-group>
101-
<mat-card-title>Card</mat-card-title>
102-
<mat-card-subtitle>Large</mat-card-subtitle>
103-
<img mat-card-lg-image>
104-
</mat-card-title-group>
112+
<mat-card-header>
113+
<mat-card-title-group>
114+
<mat-card-title>Card</mat-card-title>
115+
<mat-card-subtitle>Large</mat-card-subtitle>
116+
<img mat-card-lg-image>
117+
</mat-card-title-group>
118+
</mat-card-header>
105119
<mat-card-content>
106120
{{longText}}
107121
</mat-card-content>
108122
</mat-card>
109123

110124
<mat-card [appearance]="appearance">
111-
<mat-card-title-group>
112-
<mat-card-title>Card</mat-card-title>
113-
<mat-card-subtitle>Extra large</mat-card-subtitle>
114-
<img mat-card-xl-image>
115-
</mat-card-title-group>
125+
<mat-card-header>
126+
<mat-card-title-group>
127+
<mat-card-title>Card</mat-card-title>
128+
<mat-card-subtitle>Extra large</mat-card-subtitle>
129+
<img mat-card-xl-image>
130+
</mat-card-title-group>
131+
</mat-card-header>
116132
<mat-card-content>
117133
{{longText}}
118134
</mat-card-content>

src/material/card/card.scss

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@use 'sass:math';
21
@use '../core/mdc-helpers/mdc-helpers';
32
@use '@material/card' as mdc-card;
43

@@ -44,13 +43,6 @@ $mat-card-default-padding: 16px !default;
4443
// Apply default padding for the header region. Omit any bottom padding because we assume
4544
// this region will be followed by another region that includes top padding.
4645
padding: $mat-card-default-padding $mat-card-default-padding 0;
47-
48-
// When a subtitle is inside of a header, we want to move it up slightly to reduce the space with
49-
// the title, and add a margin bottom to create space underneath the header.
50-
.mat-mdc-card-subtitle {
51-
margin-top: -(math.div($mat-card-default-padding, 2));
52-
margin-bottom: $mat-card-default-padding;
53-
}
5446
}
5547

5648
// Primary card content. MDC does not have a pre-made section for primary content.
@@ -81,10 +73,7 @@ $mat-card-default-padding: 16px !default;
8173
// and subtitle go first (projected into a single div), followed by the media.
8274
display: flex;
8375
justify-content: space-between;
84-
85-
// Apply default padding for the title-group region. Omit any bottom padding because we assume
86-
// this region will be followed by another region that includes top padding.
87-
padding: $mat-card-default-padding $mat-card-default-padding 0;
76+
width: 100%;
8877
}
8978

9079
// Avatar image for a card. MDC does not specifically have a card avatar or a "common" avatar.
@@ -96,10 +85,20 @@ $mat-card-default-padding: 16px !default;
9685
width: $mat-card-header-size;
9786
border-radius: 50%;
9887
flex-shrink: 0;
88+
margin-bottom: $mat-card-default-padding;
9989

10090
// Makes `<img>` tags behave like `background-size: cover`. Not supported
10191
// in IE, but we're using it as a progressive enhancement.
10292
object-fit: cover;
93+
94+
// When a title and subtitle are used alongside an avatar,
95+
// reduce the spacing between them to better align with the avatar.
96+
& ~ .mat-mdc-card-header-text {
97+
.mat-mdc-card-subtitle,
98+
.mat-mdc-card-title {
99+
line-height: normal;
100+
}
101+
}
103102
}
104103

105104
// Specifically sized small image, specific to Angular Material.

0 commit comments

Comments
 (0)