Skip to content

Commit 89d16b2

Browse files
devversionjelbourn
authored andcommitted
fix(card): images in title-group overlapping content (#12205)
* Fixes that `mat-card-$breakpoint-image` images overlap the card content when placed inside of the title group. Fixes #10031
1 parent 8e63656 commit 89d16b2

File tree

3 files changed

+76
-18
lines changed

3 files changed

+76
-18
lines changed

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

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@
33
Hello
44
</mat-card>
55

6-
<mat-card>
7-
<mat-card-title-group>
8-
<mat-card-title>Card with title</mat-card-title>
9-
<mat-card-subtitle>Subtitle</mat-card-subtitle>
10-
<img mat-card-md-image>
11-
</mat-card-title-group>
12-
</mat-card>
13-
146
<mat-card>
157
<mat-card-subtitle>Subtitle</mat-card-subtitle>
168
<mat-card-title>Card with title and footer</mat-card-title>
179
<mat-card-content>
1810
<p>This is supporting text.</p>
19-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
11+
<p>{{longText}}</p>
2012
</mat-card-content>
2113
<mat-card-actions>
2214
<button mat-button>LIKE</button>
@@ -32,7 +24,7 @@
3224
<mat-card-title>Card with title, footer, and inset-divider</mat-card-title>
3325
<mat-card-content>
3426
<p>This is supporting text.</p>
35-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
27+
<p>{{longText}}</p>
3628
</mat-card-content>
3729
<mat-divider [inset]="true"></mat-divider>
3830
<mat-card-actions>
@@ -75,4 +67,51 @@
7567
<button mat-button>Second</button>
7668
</mat-card-actions>
7769
</mat-card>
70+
71+
<hr>
72+
<h2>Cards with media area</h2>
73+
74+
<mat-card>
75+
<mat-card-title-group>
76+
<mat-card-title>Card</mat-card-title>
77+
<mat-card-subtitle>Small</mat-card-subtitle>
78+
<img mat-card-sm-image>
79+
</mat-card-title-group>
80+
<mat-card-content>
81+
{{longText}}
82+
</mat-card-content>
83+
</mat-card>
84+
85+
<mat-card>
86+
<mat-card-title-group>
87+
<mat-card-title>Card</mat-card-title>
88+
<mat-card-subtitle>Medium</mat-card-subtitle>
89+
<img mat-card-md-image>
90+
</mat-card-title-group>
91+
<mat-card-content>
92+
{{longText}}
93+
</mat-card-content>
94+
</mat-card>
95+
96+
<mat-card>
97+
<mat-card-title-group>
98+
<mat-card-title>Card</mat-card-title>
99+
<mat-card-subtitle>Large</mat-card-subtitle>
100+
<img mat-card-lg-image>
101+
</mat-card-title-group>
102+
<mat-card-content>
103+
{{longText}}
104+
</mat-card-content>
105+
</mat-card>
106+
107+
<mat-card>
108+
<mat-card-title-group>
109+
<mat-card-title>Card</mat-card-title>
110+
<mat-card-subtitle>Extra large</mat-card-subtitle>
111+
<img mat-card-xl-image>
112+
</mat-card-title-group>
113+
<mat-card-content>
114+
{{longText}}
115+
</mat-card-content>
116+
</mat-card>
78117
</div>

src/demo-app/card/card-demo.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@ import {Component} from '@angular/core';
1515
templateUrl: 'card-demo.html',
1616
styleUrls: ['card-demo.css'],
1717
})
18-
export class CardDemo {}
18+
export class CardDemo {
19+
longText = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor ' +
20+
'incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud ' +
21+
'exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor' +
22+
' in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur' +
23+
' sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id ' +
24+
'est laborum.';
25+
}

src/lib/card/card.scss

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ $mat-card-header-size: 40px !default;
7474
margin: 0 -24px 16px -24px;
7575
}
7676

77-
.mat-card-xl-image {
78-
width: 240px;
79-
height: 240px;
80-
margin: -8px;
81-
}
82-
8377
.mat-card-footer {
8478
// The negative margins pulls out the element, countering the padding
8579
// to get the footer to be flush against the side of the card.
@@ -117,7 +111,10 @@ $mat-card-header-size: 40px !default;
117111

118112
// images grouped with title in title-group layout
119113
%mat-card-title-img {
120-
margin: -8px 0;
114+
// As per Material Design specifications, the images exceed the *top* content-box and take
115+
// up some space. The margin below is necessary because otherwise space of the actual card
116+
// content will be overlapped.
117+
margin: -8px 0 8px 0;
121118
}
122119

123120
.mat-card-title-group {
@@ -144,6 +141,21 @@ $mat-card-header-size: 40px !default;
144141
height: 152px;
145142
}
146143

144+
// This should normally also extend the `%mat-card-title-img`, but in order to avoid breaking
145+
// changes, we need to keep the horizontal margin reversion for now.
146+
// See: https://github.com/angular/material2/issues/12203
147+
.mat-card-xl-image {
148+
width: 240px;
149+
height: 240px;
150+
margin: -8px;
151+
152+
// Special treatment inside title group in order to fix the media areas inside of a title-group.
153+
// This can be removed once #12203 has been addressed.
154+
.mat-card-title-group > & {
155+
@extend %mat-card-title-img;
156+
}
157+
}
158+
147159
// MEDIA QUERIES
148160

149161
@media ($mat-xsmall) {

0 commit comments

Comments
 (0)