Angular Material 陰影使用
阿新 • • 發佈:2018-12-17
Angular Material 陰影使用
依託於 Angular Material 庫,可以直接使用通用的符合 Material Design 風格的陰影。
使用
使用方式有兩種:
- 外聯樣式設定,即在
css
或scss
中設定 - 通過class名稱設定,即 元素的
class
名稱
方式一:外聯樣式使用
- 在
scss
或css
檔案中匯入
@import '[email protected]/material/theming';
- 在
class
名稱或者id
內設定
.my-custom-button { @include mat-elevation(2); }
其中mat-elevation(2)
這個函式需要傳遞一個數值型別的引數,這個引數值越大陰影越大。
編譯後的陰影樣式為:
.my-custom-button {
box-shadow:
0px 3px 1px -2px rgba(0, 0, 0, 0.2),
0px 2px 2px 0px rgba(0, 0, 0, 0.14),
0px 1px 5px 0px rgba(0, 0, 0, 0.12);
}
方式二:通過元素class設定
不需要匯入直接使用,通過使用 mat-elevation-zX
這個通用的class
來設定,其中X
是數字,代表陰影的高度,也可理解為陰影的程度,值越大陰影越大。
<div class="mat-elevation-z24">
<p>你好</p>
</div>
備註
Angular Material 常用的陰影數值:
Elevation(dp) | Component |
---|---|
24 | Dialog Picker |
16 | Nav Drawer Right drawer Modal bottom Sheet |
12 | Floating action button(FAB - pressed) |
9 | Sub menu ( +1 dp for each sub menu ) |
8 | Bottom navigation bar Menu Card Raised button ( pressed state ) |
6 | Floating action button ( FAB - resting elevation ) Snackbar |
4 | App Bar |
3 | Refresh indicator Quick entry / Search bar ( scrolled state ) |
2 | Caed ( resting elevation ) * Raised button ( resting elevation ) Quick entry / Search bar ( scrolled state ) |
1 | Switch |