Skip to content

Commit b8309d6

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 0f9c1e6 commit b8309d6

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ $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;
25-
2622
// Titles and subtitles can be set on native header elements which come with
2723
// their own margin. Clear it since the spacing is done using `padding`.
2824
margin: 0;
25+
26+
.mat-mdc-card-avatar ~ .mat-mdc-card-header-text & {
27+
// Apply default padding for a text content region. Omit any bottom padding because we assume
28+
// this region will be followed by another region that includes top padding.
29+
padding: $mat-card-default-padding $mat-card-default-padding 0;
30+
}
2931
}
3032

3133
// Header section at the top of a card. MDC does not have a pre-made header section for cards.
@@ -128,8 +130,11 @@ $mat-card-default-padding: 16px !default;
128130
// `mat-card-title-group` since the padding is captured by parent container already.
129131
.mat-mdc-card-subtitle ~ .mat-mdc-card-title,
130132
.mat-mdc-card-title ~ .mat-mdc-card-subtitle,
131-
.mat-mdc-card-header .mat-mdc-card-title,
132-
.mat-mdc-card-header .mat-mdc-card-subtitle,
133+
134+
// The `.mat-mdc-card-header-text` here is redundant since the header text
135+
// wrapper is always there in the header, but we need the extra specificity.
136+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-title,
137+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-subtitle,
133138
.mat-mdc-card-title-group .mat-mdc-card-title,
134139
.mat-mdc-card-title-group .mat-mdc-card-subtitle {
135140
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)