Created
July 24, 2020 11:26
-
-
Save bennadel/90a6b56e263b6b61ba4fac2534f1a429 to your computer and use it in GitHub Desktop.
Using Negative Box-Shadow Spread To Communicate Depth In CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title> | |
Using Negative Box-Shadow Spread To Communicate Depth In CSS | |
</title> | |
</head> | |
<body> | |
<h1> | |
Using Negative Box-Shadow Spread To Communicate Depth In CSS | |
</h1> | |
<div class="container"> | |
<div class="tile tile--a"> | |
No Spread | |
</div> | |
<div class="tile tile--b"> | |
-5px Spread | |
</div> | |
</div> | |
<style type="text/css"> | |
.tile { | |
box-shadow: 0px 1px 0px 0px rgba( 0, 0, 0, 0.3 ) ; | |
transition-duration: 500ms ; | |
transition-property: box-shadow, transform ; | |
transition-timing-function: ease-in-out ; | |
} | |
.tile:hover { | |
transform: translateY( -30px ) ; | |
} | |
.tile--a:hover { | |
/* No spread. */ | |
box-shadow: 0px 40px 20px 0px rgba( 0, 0, 0, 0.15 ) ; | |
} | |
.tile--b:hover { | |
/* -5px spread pulls edges of shadow in on all sides. */ | |
box-shadow: 0px 42px 20px -5px rgba( 0, 0, 0, 0.15 ) ; | |
} | |
/* -- Non-demo-related styles. -- */ | |
.container { | |
display: flex ; | |
justify-content: space-around ; | |
margin-top: 100px ; | |
} | |
.tile { | |
align-items: center ; | |
background-color: #fafafa ; | |
border: 1px solid #ccc ; | |
border-radius: 8px 8px 8px 8px ; | |
color: #777777 ; | |
display: flex ; | |
font-family: monospace ; | |
font-size: 18px ; | |
height: 150px ; | |
justify-content: center ; | |
width: 250px ; | |
} | |
</style> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment