From 22ae587cd4a8c684aa3be795c5f4751a592408a7 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 23 Aug 2018 16:50:00 +0200 Subject: [PATCH] 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 --- src/demo-app/card/card-demo.html | 59 ++++++++++++++++++++++++++------ src/demo-app/card/card-demo.ts | 9 ++++- src/lib/card/card.scss | 26 ++++++++++---- 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/demo-app/card/card-demo.html b/src/demo-app/card/card-demo.html index bde2eee3829b..4c5c31e62053 100644 --- a/src/demo-app/card/card-demo.html +++ b/src/demo-app/card/card-demo.html @@ -3,20 +3,12 @@ Hello - - - Card with title - Subtitle - - - - Subtitle Card with title and footer

This is supporting text.

-

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.

+

{{longText}}

@@ -32,7 +24,7 @@ Card with title, footer, and inset-divider

This is supporting text.

-

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.

+

{{longText}}

@@ -75,4 +67,51 @@
+ +
+

Cards with media area

+ + + + Card + Small + + + + {{longText}} + + + + + + Card + Medium + + + + {{longText}} + + + + + + Card + Large + + + + {{longText}} + + + + + + Card + Extra large + + + + {{longText}} + + diff --git a/src/demo-app/card/card-demo.ts b/src/demo-app/card/card-demo.ts index 7a2bcbbf1282..58a635617488 100644 --- a/src/demo-app/card/card-demo.ts +++ b/src/demo-app/card/card-demo.ts @@ -15,4 +15,11 @@ import {Component} from '@angular/core'; templateUrl: 'card-demo.html', styleUrls: ['card-demo.css'], }) -export class CardDemo {} +export class CardDemo { + longText = '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.'; +} diff --git a/src/lib/card/card.scss b/src/lib/card/card.scss index 43f9bf27b886..ebbb3e475f5a 100644 --- a/src/lib/card/card.scss +++ b/src/lib/card/card.scss @@ -74,12 +74,6 @@ $mat-card-header-size: 40px !default; margin: 0 -24px 16px -24px; } -.mat-card-xl-image { - width: 240px; - height: 240px; - margin: -8px; -} - .mat-card-footer { // The negative margins pulls out the element, countering the padding // to get the footer to be flush against the side of the card. @@ -117,7 +111,10 @@ $mat-card-header-size: 40px !default; // images grouped with title in title-group layout %mat-card-title-img { - margin: -8px 0; + // As per Material Design specifications, the images exceed the *top* content-box and take + // up some space. The margin below is necessary because otherwise space of the actual card + // content will be overlapped. + margin: -8px 0 8px 0; } .mat-card-title-group { @@ -144,6 +141,21 @@ $mat-card-header-size: 40px !default; height: 152px; } +// This should normally also extend the `%mat-card-title-img`, but in order to avoid breaking +// changes, we need to keep the horizontal margin reversion for now. +// See: https://github.com/angular/material2/issues/12203 +.mat-card-xl-image { + width: 240px; + height: 240px; + margin: -8px; + + // Special treatment inside title group in order to fix the media areas inside of a title-group. + // This can be removed once #12203 has been addressed. + .mat-card-title-group > & { + @extend %mat-card-title-img; + } +} + // MEDIA QUERIES @media ($mat-xsmall) {