Skip to content

Commit 27f25e5

Browse files
committed
fix(material/card): remove extra margin if header doesn't have an avatar
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 4f8e87e commit 27f25e5

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@
6060
</mat-card-content>
6161
</mat-card>
6262

63+
<!-- Used to test header without an avatar. -->
64+
<mat-card>
65+
<mat-card-header>
66+
<mat-card-title>Header title</mat-card-title>
67+
<mat-card-subtitle>Header subtitle</mat-card-subtitle>
68+
</mat-card-header>
69+
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
70+
<mat-card-content>
71+
<p>Here is some content</p>
72+
</mat-card-content>
73+
</mat-card>
74+
6375
<mat-card class="demo-card-blue mat-card-flat">
6476
<mat-card-title>Easily customizable</mat-card-title>
6577
<mat-card-actions>

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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ $mat-card-default-padding: 16px !default;
1919
// Custom elements default to `display: inline`. Reset to 'block'.
2020
display: block;
2121

22-
// Apply default padding for a text content region. Omit any bottom padding because we assume
23-
// this region will be followed by another region that includes top padding.
24-
padding: $mat-card-default-padding $mat-card-default-padding 0;
22+
.mat-mdc-card-avatar ~ .mat-mdc-card-header-text & {
23+
// Apply default padding for a text content region. Omit any bottom padding because we assume
24+
// this region will be followed by another region that includes top padding.
25+
padding: $mat-card-default-padding $mat-card-default-padding 0;
26+
}
2527
}
2628

2729
// Header section at the top of a card. MDC does not have a pre-made header section for cards.
@@ -124,8 +126,11 @@ $mat-card-default-padding: 16px !default;
124126
// `mat-card-title-group` since the padding is captured by parent container already.
125127
.mat-mdc-card-subtitle ~ .mat-mdc-card-title,
126128
.mat-mdc-card-title ~ .mat-mdc-card-subtitle,
127-
.mat-mdc-card-header .mat-mdc-card-title,
128-
.mat-mdc-card-header .mat-mdc-card-subtitle,
129+
130+
// The `.mat-mdc-card-header-text` here is redundant since the header text
131+
// wrapper is always there in the header, but we need the extra specificity.
132+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-title,
133+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-subtitle,
129134
.mat-mdc-card-title-group .mat-mdc-card-title,
130135
.mat-mdc-card-title-group .mat-mdc-card-subtitle {
131136
padding-top: 0;

src/material/card/card.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ $header-size: 40px !default;
103103
}
104104

105105
.mat-card-header-text {
106-
margin: 0 $padding;
106+
&:not(:first-child) {
107+
margin-left: $padding;
108+
}
109+
110+
[dir='rtl'] & {
111+
margin-left: 0;
112+
113+
&:not(:first-child) {
114+
margin-right: $padding;
115+
}
116+
}
107117
}
108118

109119
.mat-card-avatar {

0 commit comments

Comments
 (0)