1- # Setting Element Elevation
1+ # Applying Elevation
22
3- Angular Material's elevation classes and mixins allow you to add separation between elements along
4- the z-axis. All material design elements have resting elevations. In addition, some elements may
5- change their elevation in response to user interaction. The
6- [ Material Design spec] ( https://material.io/design/environment/elevation.html )
7- explains how to best use elevation.
3+ [ The Material Design specification] [ material-elevation ] gives guidance on expressing elevation on
4+ UI elements by adding shadows. Angular Material provides CSS classes and Sass mixins for adding
5+ these shadows.
86
9- Angular Material provides two ways to control the elevation of elements: predefined CSS classes
10- and mixins.
7+ [ material-elevation ] : https://material.io/design/environment/elevation.html
118
12- ## Predefined CSS classes
9+ ## Elevation CSS classes
1310
14- The easiest way to add elevation to an element is to simply add one of the predefined CSS classes
15- ` mat-elevation-z# ` where ` # ` is the elevation number you want, 0-24. Dynamic elevation can be
16- achieved by switching elevation classes:
11+ The ` core-theme ` Sass mixin, described in the [ theming guide] [ ] , emits CSS classes for applying
12+ elevation. These classes follow the pattern ` mat-elevation-z# ` , where ` # ` is the elevation number
13+ you want, from 0 to 24. These predefined classes use the CSS ` box-shadow ` settings defined by the
14+ Material Design specification.
15+
16+ You can dynamically change elevation on an element by swapping elevation CSS classes.
1717
1818``` html
1919<div [class.mat-elevation-z2] =" !isActive" [class.mat-elevation-z8] =" isActive" ></div >
2020```
2121
2222<!-- example(elevation-overview) -->
2323
24- ## Mixins
25-
26- Elevations can also be added in CSS via the ` elevation ` mixin, which takes a number 0-24
27- indicating the elevation of the element as well as optional arguments for the elevation shadow's
28- color tone and opacity.
24+ [ theming-guide ] : https://material.angular.io/guide/theming#applying-a-theme-to-components
2925
30- Since an elevation shadow consists of multiple shadow components of varying opacities, the
31- ` $opacity ` argument of the mixin is considered a factor by which to scale these initial values
32- rather than an absolute value.
26+ ## Elevation Sass mixins
3327
34- In order to use the mixin, you must import ` ~@angular/material ` :
28+ In addition to the predefined CSS classes, you can apply elevation styles using the ` elevation `
29+ Sass mixin. This mixin accepts a ` $zValue ` and an optional ` $color ` . The ` $zValue ` is a number from
30+ 0 to 24, representing the semantic elevation of the element, that controls the intensity of the
31+ box-shadow. You can use the ` $color ` parameter to further customize the shadow appearance.
3532
3633``` scss
3734@use ' ~@angular/material' as mat ;
@@ -47,14 +44,23 @@ In order to use the mixin, you must import `~@angular/material`:
4744}
4845```
4946
50- For convenience, you can use the ` elevation-transition ` mixin to add a transition when the
51- elevation changes:
47+ ### Overridable elevation
48+
49+ When authoring a component, you may want to specify a default elevation that the component consumer
50+ can override. You can accomplish this by using the ` overridable-elevation ` Sass mixin. This behaves
51+ identically to the ` elevation ` mixin, except that the styles only apply when the element does not
52+ have a CSS class matching the pattern ` mat-elevation-z# ` , as described in
53+ [ Elevation CSS classes] ( #elevation-css-classes ) above.
54+
55+ ### Animating elevation
56+
57+ You can use the ` elevation-transition ` mixin to add a transition when elevation changes.
5258
5359``` scss
5460@use ' ~@angular/material' as mat ;
5561
5662.my-class {
57- @include mat .elevation-transition ;
63+ @include mat .elevation-transition () ;
5864 @include mat .elevation (2 );
5965
6066 & :active {
0 commit comments