Open ChristopherSnay opened 2 years ago
confirmed: https://stackblitz.com/edit/angular-v7wcjs?file=src%2Fmain.ts
notice, that @includes with elevation helpers does not work on mat-card, too:
mat-card {
@include mat.elevation(8);
}
I spent some time trying to fix this in #26098, but it ended up breaking too many internal apps. For future reference, here's what I tried:
private-theme-overridable-elevation
mixin instead of private-theme-elevation
. This is the correct way to fix it, but it ends up increasing the specificity too much which was breaking some style overrides.box-shadow
to a CSS variable and setting variable in the mat-elevation-z*
classes. This reduces the specificity, but appears not to be enough for some cases.mat-card
tag selector to set the box-shadow
instead of .mat-mdc-card
. This seems to reduce the specificity a bit too much and is against our CSS selector guidelines.Hi,
Same problem with mat-elevation-z* classes and elevation helpers: no elevation anymore. By the way, i don't know if this is done on purpose, but it seems running "mdc-migration" command in not listed on angular material 14 -> 15 migration guide.
FI class styles are applied, but they are immediately preceeded by mdc styles. So basicaly they are ignored
By the way, i don't know if this is done on purpose, but it seems running "mdc-migration" command in not listed on angular material 14 -> 15 migration guide.
It adds the step if you check the "I use Angular material" checkbox. The migration tool is mentioned in the Read Further link
In Angular Material v15, many of the components have been refactored to be based on the official Material Design Components for Web (MDC). This change affected the DOM and CSS classes of many components. Read further
Will this be fixed in v15.1.0 or do we have to employ our workarounds for now?
It won't be fixed for 15.1.0.
I noticed that the mdc-migration schematic is changing cards to use outline
for appearance
, when they didn't originally use it. Was that done intentionally as a stopgap because of the elevation styles not working? If not, I can open a separate issue for that.
This is working. mat-card-content class="mat-elevation-z8"
Use mat-card-content tag.
That doesn't really give desired results... (should be the whole card)
sounds a bit crazy, but you need to move all your mat-card to the outer content;
mat-card
mat-card-content class=" .. elevation.."
mat-card (the one that u want)
Oof. I mean, that's good to know as a workaround, but that's not really an acceptable fix.
u got it, it is a crazy workaround, until someone in google figured out a fix.
Any news on this, it has been opened for more than 2 months. I would rather not implement a workaround.
Still not working "@angular/material": "^15.2.3",
Any updates on this?
Adding these lines in global-css worked for me (workaround)
.mat-mdc-card.mat-elevation-z6 {
@include mat.elevation(6);
}
.mat-mdc-card.mat-elevation-z8 {
@include mat.elevation(8);
}
.mat-mdc-card.mat-elevation-z10 {
@include mat.elevation(10);
}
// add more mat-elevations that are needed...
Version: @angular/material: 15.2.4
In that spirit, this should re-create all of them.
@for $i from 0 through 24 {
.mat-mdc-card.mat-elevation-z#{$i} {
@include mat.elevation($i);
}
}
Try to just grow the height of mat-card, works for me the elevation.
Try to just grow the height of mat-card, works for me the elevation.
What does this mean?
I have this issue, with same version, but for some reason the height of mat-card box was the exactly size of card, and for this reason looks like mat-elevation-zx doesn't work, if you grow the height the mat-elevation-zx appear correctly. Sorry I don't speak english very well, do you understand?
Same for mat-menu. The fix from @simonbauer-gepardec works:
@for $i from 0 through 24 {
.mat-mdc-menu-panel.mat-elevation-z#{$i} {
@include mat.elevation($i);
}
}
I am using Angular Material ^15.2.6, and I do have an extra class called mat-mdc-elevation-specific added automatically to the card. So a workaround can be that you add this class to the mat-card as well (gives specificity boost :)
<mat-card class="mat-mdc-elevation-specific mat-elevation-z4">
...
A workaround until better comes up.
This is working. mat-card-content class="mat-elevation-z8"
Use mat-card-content tag.
WORKS! THANK YOU SO MUCH!
Doesnt work in 16.0.1
Also running into this issue. From what I can tell, .mat-elevation-z* is being overridden by .mat-mdc-card which is pulling from the theme below the elevation style. This seems like a pretty obvious oversight in how styling order is applied.
CSS classes are posted in order.
.mat-mdc-card {
...
box-shadow: var(--mdc-elevated-card-container-elevation);
...
}
**What I want**
<style>
.mat-elevation-z8, .mat-mdc-elevation-specific.mat-elevation-z8 {
box-shadow: 0px 5px 5px -3px rgba(0, 0, 0, 0.2), 0px 8px 10px 1px rgba(0, 0, 0, 0.14), 0px 3px 14px 2px rgba(0, 0, 0, 0.12);
}
**What I'm getting**
.mat-mdc-card {
...
--mdc-elevated-card-container-elevation: 0px 2px 1px -1px rgba(0, 0, 0, 0.2), 0px 1px 1px 0px rgba(0, 0, 0, 0.14), 0px 1px 3px 0px rgba(0, 0, 0, 0.12);
...
}
The styling fix posted above works, or I could just roll my own. But this is pretty clearly not working as expected.
Adding these lines in global-css worked for me (workaround)
.mat-mdc-card.mat-elevation-z6 { @include mat.elevation(6); } .mat-mdc-card.mat-elevation-z8 { @include mat.elevation(8); } .mat-mdc-card.mat-elevation-z10 { @include mat.elevation(10); } // add more mat-elevations that are needed...
Version: @angular/material: 15.2.4
This works in angular 16 also.
We also have to add the following line on the top of style.scss file. Reference
@use "@angular/material" as mat;
Most workarounds posted here (those declaring CSS classes) aren't working for me in 15.2,9, a year after this issue was opened. Only the nested card solution seems to work with a card wrapping a card-content, wrapping another card. Something interesting though: I'm attempting to show an elevated card inside a mat-tab
which is animated, as default. During the animation the card elevation is visible, it disappears as soon as the animation ends.
Maybe this can help somebody track down the issue more easily.
This is still an issue in 16.2.8
I am using Angular Material ^15.2.6, and I do have an extra class called mat-mdc-elevation-specific added automatically to the card. So a workaround can be that you add this class to the mat-card as well (gives specificity boost :)
<mat-card class="mat-mdc-elevation-specific mat-elevation-z4"> ...
A workaround until better comes up.
This workaround works for mat-sidenav too with Material 17 :-)
when fixed?
Is there a way to style this globally somehow ?
Is there a way to style this globally somehow ?
https://github.com/angular/components/issues/26094#issuecomment-1490245622
why is this still not fixed? Even the demo isn't working. https://material.angular.io/guide/elevation#overridable-elevation
dead project? when will google shutdown angular?
Any updates on this? The imports trick worked in my global styles.scss.
any updates on this?
🤦♂️ Still broken in ng 18.2.4, workaround (https://github.com/angular/components/issues/26094#issuecomment-1531183165)_ works for me.
Just tested and it's still broken in 19.0 - i kept the
@for $i from 0 through 24 {
mat-card.mat-elevation-z#{$i} {
@include mat.elevation($i);
}
}
workaround in my styles.scss
Is this a regression?
The previous version in which this bug was not present was
14
Description
I have some mat-cards with specific elevations set, like for example:
class=mat-elevation-z4
After the upgrade from 14 to 15, the cards are no longer affected by any mat-elevation classes I add.Reproduction
Steps to reproduce:
<mat-card class="mat-elevation-z8">test</mat-card>
Expected Behavior
Expecting the mat-elevation-zx classes to modify the mat-card's elevation.
Actual Behavior
elevation is not affected by adding, for example,
class="mat-elevation-z8"
Environment