Skip to content

Commit 557f8bc

Browse files
authored
fix(material-experimental/mdc-card): remove extra margin if header doesn't have an avatar (#19072)
The card header margin was set up assuming that there would always be an avatar element, but that's not always the case. These changes add an extra check to avoid the extra margin. Fixes #19069.
1 parent 2d8fd9d commit 557f8bc

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,16 @@ <h2>Cards with media area</h2>
118118
</mat-card-content>
119119
</mat-card>
120120

121+
<!-- Used to test header without an avatar. -->
122+
<mat-card [appearance]="appearance">
123+
<mat-card-header>
124+
<mat-card-title>Header title</mat-card-title>
125+
<mat-card-subtitle>Header subtitle</mat-card-subtitle>
126+
</mat-card-header>
127+
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
128+
<mat-card-content>
129+
<p>Here is some content</p>
130+
</mat-card-content>
131+
</mat-card>
121132

122133
</div>

src/material-experimental/mdc-card/card.scss

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ $mat-card-default-padding: 16px !default;
2222
// Custom elements default to `display: inline`. Reset to 'block'.
2323
display: block;
2424

25-
// Apply default padding for a text content region. Omit any bottom padding because we assume
26-
// this region will be followed by another region that includes top padding.
27-
padding: $mat-card-default-padding $mat-card-default-padding 0;
28-
2925
// Titles and subtitles can be set on native header elements which come with
3026
// their own margin. Clear it since the spacing is done using `padding`.
3127
margin: 0;
28+
29+
.mat-mdc-card-avatar ~ .mat-mdc-card-header-text & {
30+
// Apply default padding for a text content region. Omit any bottom padding because we assume
31+
// this region will be followed by another region that includes top padding.
32+
padding: $mat-card-default-padding $mat-card-default-padding 0;
33+
}
3234
}
3335

3436
// Header section at the top of a card. MDC does not have a pre-made header section for cards.
@@ -131,8 +133,11 @@ $mat-card-default-padding: 16px !default;
131133
// `mat-card-title-group` since the padding is captured by parent container already.
132134
.mat-mdc-card-subtitle ~ .mat-mdc-card-title,
133135
.mat-mdc-card-title ~ .mat-mdc-card-subtitle,
134-
.mat-mdc-card-header .mat-mdc-card-title,
135-
.mat-mdc-card-header .mat-mdc-card-subtitle,
136+
137+
// The `.mat-mdc-card-header-text` here is redundant since the header text
138+
// wrapper is always there in the header, but we need the extra specificity.
139+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-title,
140+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-subtitle,
136141
.mat-mdc-card-title-group .mat-mdc-card-title,
137142
.mat-mdc-card-title-group .mat-mdc-card-subtitle {
138143
padding-top: 0;

0 commit comments

Comments
 (0)