<div class="wrapper">
<form action="">
<label for="direction">Choose the transition position</label>
<select name="direction" id="direction">
<option value="left center">left center</option>
<option value="right center">right center</option>
<option value="center top">center top</option>
<option value="center bottom">center bottom</option>
<option value="center">center</option>
<option value="left top">left top</option>
<option value="right top">right top</option>
<option value="left bottom">left bottom</option>
<option value="right bottom">right bottom</option>
</select>
</form>
<ul class="stats">
<li class="stats__item">
<h3>Number of users</h3>
<p>345</p>
</li>
<li class="stats__item">
<h3>Revenue</h3>
<p>$45,000</p>
</li>
<li class="stats__item">
<h3>Refunds</h3>
<p>$350</p>
</li>
</ul>
<p class="demo">This is a demo from my article <a href="https://ishadeed.com/article/clip-path/">Understanding Clip Path in CSS</a></p>
</div>
:root {
--pos: left center;
--size: 0;
}
.wrapper {
max-width: 744px;
margin: 2rem auto;
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
grid-gap: 1rem;
}
.stats__item {
position: relative;
display: flex;
flex-direction: column;
background-color: #fff;
padding: 1rem;
border-radius: 5px;
box-shadow: 0 3px 10px 0 rgba(#000, 0.1);
overflow: hidden;
cursor: pointer;
h3,
p {
/* z-index works becuase those are flex childs.. */
z-index: 1;
transition: 0.25s linear;
}
h3 {
color: grey;
font-size: 0.8rem;
}
p {
font-size: 1.125rem;
font-weight: bold;
}
&:before {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: #7777e9;
clip-path: circle(var(--size) at var(--pos));
transition: 0.4s linear;
}
&:hover {
h3,
p {
color: #fff;
}
&:before {
--size: 300px;
}
}
}
form {
margin-bottom: 1rem;
@media (min-width: 680px) {
margin-bottom: 3rem;
}
}
.demo {
margin-top: 2rem;
font-size: 14px;
}
body {
font-family: "system-ui";
line-height: 1.4;
padding: 1rem;
background-color: #f7f7f7;
}
* {
box-sizing: border-box;
}
View Compiled
const transPos = document.querySelector("#direction");
transPos.addEventListener("input", function () {
let pos = this.value;
document.documentElement.style.setProperty("--pos", pos);
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.