<div class="box box__slower">Normal Box Shadow Transition (Slower)</div>
<div class="box box__faster">Pseudo-Element Opacity Transition (Faster)</div>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
min-height: 100vh;
font-family: "Exo", Arial, sans-serif;
background-color: rgb(237 242 247);
padding: 20px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
gap: 60px;
}
.box {
aspect-ratio: 16 / 9;
background-color: #fff;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
font-size: clamp(20px, 3vw + 2rem, 30px);
}
.box__slower {
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
}
.box__slower:hover {
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.7);
transition: box-shadow 500ms;
}
.box__faster {
position: relative;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
}
.box__faster::after {
content: "";
position: absolute;
inset: 0;
border-radius: 10px;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12), 0 2px 2px rgba(0, 0, 0, 0.12),
0 4px 4px rgba(0, 0, 0, 0.12), 0 8px 8px rgba(0, 0, 0, 0.12),
0 16px 16px rgba(0, 0, 0, 0.12);
opacity: 0;
transition: opacity 500ms;
}
.box__faster:hover::after {
opacity: 1;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.