<button>Apply changes</button>
*,
*::before,
*::after {
box-sizing: border-box;
font-family: sans-serif;
}
/**
* Unperformant ugly color shift just to demonstrate
* it works with all backgrounds.
*/
@keyframes colorShift {
0% {
background-color: #ee9ca7;
}
25% {
background-color: #ffdde1;
}
50% {
background-color: #6dd5fa;
}
75% {
background-color: #fdc830;
}
100% {
background-color: #f37335;
}
}
body {
margin: 0 auto;
display: flex;
flex-direction: column;
justify-content: space-around;
min-height: 100vh;
max-width: 20rem;
animation: colorShift 10s infinite both alternate;
}
button {
--triangle-offset-top: -6px;
--triangle-offset-left: 1rem;
position: relative;
appearance: none;
border: 0;
color: #f8f9fa;
background-color: transparent;
padding: 1em 1.5em;
font-size: inherit;
text-transform: uppercase;
font-weight: 700;
letter-spacing: 0.04em;
}
button:hover {
--triangle-offset-top: -10px;
}
button:focus {
outline: none;
}
button:focus::before {
box-shadow: inset 0 0 0 2px #ff00b4;
}
/**
* The button background. We need it to be a separate element
* since we only want to mask the background, not the contents
* or the other triangle.
*/
button::before {
content: " ";
background-color: #212529;
background: linear-gradient(to bottom, #232526, #414345);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
-webkit-mask-image:
-webkit-linear-gradient(black, black),
url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="22" height="18" viewBox="0 0 22 18"><polygon points="0 0 11 18 22 0 0 0"/></svg>');
-webkit-mask-size:
100% 100%,
22px 18px;
-webkit-mask-position:
top left,
var(--triangle-offset-left) var(--triangle-offset-top);
-webkit-mask-repeat: no-repeat;
-webkit-mask-composite: exclude;
-webkit-mask-composite: xor;
transition: all 0.2s;
border-radius: 3px;
}
/**
* The pink triangle
*/
button::after {
content: " ";
display: block;
width: 22px;
height: 18px;
position: absolute;
top: 0;
left: 0;
transform: translate(var(--triangle-offset-left), var(--triangle-offset-top));
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 18"><polygon points="3.57 2 11 14.16 18.43 2 3.57 2" fill="%23ff00b4"/></svg>');
background-position: top left;
background-size: 100% 100%;
z-index: 1;
transition: all 0.2s;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.