Gradient & border opacity
Gradient & border opacity
by Csaba Hellinger
HTML
<button class="default">Default</button>
<button class="disabled">Disabled</button>
CSS
button {
--border-width: 5px;
position: relative;
background-clip: padding-box;
&::before {
content: '';
position: absolute;
inset: 0;
z-index: -1;
margin: calc(-1 * var(--border-width));
border-radius: inherit;
}
}
.default {
background: linear-gradient(90deg, #8df, #008) padding-box;
border: solid var(--border-width) transparent;
&::before {
background: linear-gradient(90deg, #ff0, #f00);
}
}
.disabled {
background: linear-gradient(90deg, #8dfb, #008b) padding-box;
border: solid var(--border-width) transparent;
&::before {
background: linear-gradient(90deg, #ff0b, #f00b);
}
}
/* just for the demo */
body {
background: #222;
background: url(https://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Checkerboard_pattern.svg/480px-Checkerboard_pattern.svg.png) repeat;
background-size: 10%;
margin: 2rem;
}
button {
font-size: 2rem;
color: yellow;
border-radius: 999rem;
padding: 1rem;
}