The cards on this site's homepage have two corners cut off at an angle. I wanted that without an image, a clip path or an SVG, because those cut the border, the shadow and the focus ring away too.
CSS now has a property for it. corner-shape changes what a border-radius draws: instead of a curve it can be a straight cut, a scoop or a notch. Everything that follows the box's edge follows the new shape.
View code
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cut-corner glass cards</title>
<style>
:root {
--cut: 20px;
--shape: bevel;
color-scheme: dark;
}
body {
align-content: center;
background:
radial-gradient(circle at 20% 110%, rgb(0 216 116 / 35%), transparent 45%),
radial-gradient(circle at 85% -10%, rgb(90 120 255 / 30%), transparent 45%),
#060a07;
color: rgb(255 255 255 / 90%);
display: grid;
font: 16px/1.5 system-ui, sans-serif;
gap: 28px;
margin: 0;
min-height: 100vh;
padding: 24px;
}
.cards {
display: grid;
gap: 16px;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
/* The whole trick: a radius on two corners, and a shape for them. The
border, shadow, blur and focus ring all follow the cut. */
.card {
backdrop-filter: blur(6px) saturate(120%);
background: rgb(15 27 20 / 30%);
border: 1px solid rgb(169 255 208 / 22%);
border-radius: 0 var(--cut) 0 var(--cut);
box-shadow: 0 22px 64px rgb(0 0 0 / 30%);
corner-shape: var(--shape);
min-height: 130px;
padding: 20px;
transition: border-color 200ms, translate 200ms;
}
.card:hover {
border-color: rgb(169 255 208 / 55%);
translate: 0 -4px;
}
.card small {
letter-spacing: 0.2em;
opacity: 0.6;
}
.card h2 {
font-size: 1.3rem;
font-weight: 400;
margin: 44px 0 0;
}
form {
align-items: center;
display: flex;
flex-wrap: wrap;
font-size: 0.9rem;
gap: 12px 24px;
}
label {
align-items: center;
display: flex;
gap: 8px;
}
input[type="range"] {
accent-color: #00d874;
}
#unsupported {
margin: 0;
opacity: 0.7;
}
</style>
<div class="cards">
<div class="card"><small>01</small><h2>About</h2></div>
<div class="card"><small>02</small><h2>Projects</h2></div>
<div class="card"><small>03</small><h2>Journal</h2></div>
</div>
<form>
<label>Cut <input type="range" name="cut" min="0" max="48" value="20"></label>
<label><input type="radio" name="shape" value="bevel" checked> Bevel</label>
<label><input type="radio" name="shape" value="scoop"> Scoop</label>
<label><input type="radio" name="shape" value="notch"> Notch</label>
<label><input type="radio" name="shape" value="squircle"> Squircle</label>
<label><input type="radio" name="shape" value="round"> Round</label>
</form>
<p id="unsupported" hidden>This browser doesn't shape corners yet, so they stay round.</p>
<script>
const form = document.querySelector("form");
form.addEventListener("input", () => {
document.documentElement.style.setProperty("--cut", `${form.cut.value}px`);
document.documentElement.style.setProperty("--shape", form.shape.value);
});
document.getElementById("unsupported").hidden = CSS.supports("corner-shape: bevel");
</script>
</html>
How it works
Each card has a radius on two opposite corners and one extra line:
.card {
border-radius: 0 20px 0 20px;
corner-shape: bevel;
}
The radius sets how big the cut is, and the shape says what to draw there. The glass is a translucent background with a backdrop-filter blur, and both are clipped to the same cut.
Browsers that don't shape corners yet fall back to ordinary round ones, so nothing breaks.
Comments
Loading comments…