1
- # Setting Element Elevation
1
+ # Applying Elevation
2
2
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.
8
6
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
11
8
12
- ## Predefined CSS classes
9
+ ## Elevation CSS classes
13
10
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.
17
17
18
18
``` html
19
19
<div [class.mat-elevation-z2] =" !isActive" [class.mat-elevation-z8] =" isActive" ></div >
20
20
```
21
21
22
22
<!-- example(elevation-overview) -->
23
23
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
29
25
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
33
27
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.
35
32
36
33
``` scss
37
34
@use ' ~@angular/material' as mat ;
@@ -47,14 +44,23 @@ In order to use the mixin, you must import `~@angular/material`:
47
44
}
48
45
```
49
46
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.
52
58
53
59
``` scss
54
60
@use ' ~@angular/material' as mat ;
55
61
56
62
.my-class {
57
- @include mat .elevation-transition ;
63
+ @include mat .elevation-transition () ;
58
64
@include mat .elevation (2 );
59
65
60
66
& :active {
0 commit comments