Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Design Elevation Correct CSS

I can't seem to find any official CSS code for all the box-shadows for elevation of cards for Material Design.

Calculating shadow values for all Material Design elevations

I've read these answers but they don't align with the box-shadow that Google is using on their search box on http://www.google.com when I do a quick inspection.

The box-shadow that Google is using on the search box is this CSS:

box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.08);

Is there an official CSS for all elevations?

like image 827
Tn Hn Avatar asked Jan 05 '17 10:01

Tn Hn


People also ask

What is elevation in Material Design?

Elevation (Android) Elevation is the relative depth, or distance, between two surfaces along the z-axis. Specifications: Elevation is measured in the same units as the x and y axes, typically in density-independent pixels (dp).

What is class mat elevation z8?

the mat-elevation-z8 class is an Angular Material elevation class that allows you to add separation between elements along the z-axis.

What is DP in shadow?

A dp is equal to one physical pixel on a screen with a density of 160. To calculate dp: dp = (width in pixels * 160) / screen density.


2 Answers

According to https://material.io/design/environment/elevation.html by Google , Cards should have an elevation of 2dp when resting and 8dp when raised.

enter image description here

And according to https://pixplicity.com,

ldpi    @ 1.00dp    = 0.75px    = 1.00sp    = 0.16mm    = 0.01in    = 0.45pt
mdpi    @ 1.00dp    = 1.00px    = 1.00sp    = 0.16mm    = 0.01in    = 0.45pt
tvdpi   @ 1.00dp    = 1.33px    = 1.00sp    = 0.16mm    = 0.01in    = 0.45pt
hdpi    @ 1.00dp    = 1.50px    = 1.00sp    = 0.16mm    = 0.01in    = 0.45pt
xhdpi   @ 1.00dp    = 2.00px    = 1.00sp    = 0.16mm    = 0.01in    = 0.45pt
xxhdpi  @ 1.00dp    = 3.00px    = 1.00sp    = 0.16mm    = 0.01in    = 0.45pt
xxxhdpi @ 1.00dp    = 4.00px    = 1.00sp    = 0.16mm    = 0.01in    = 0.45pt

Try using these conversions to get the box shadow size in css.

Note: On desktop, the resting elevation is 0dp

like image 76
Collins Abitekaniza Avatar answered Nov 15 '22 04:11

Collins Abitekaniza


here you can find official guide for elevation: https://material.io/develop/web/components/elevation/

There is a library of styles you can install it like that: npm install @material/elevation

like image 23
Akmal Anvarov Avatar answered Nov 15 '22 05:11

Akmal Anvarov