Gradient & border opacity 2
Gradient & border opacity 2
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 {
/* decrease the alpha value in these colors to see that border will not affect background */
background: linear-gradient(90deg, #8dfb, #008b) padding-box;
border: solid var(--border-width) transparent;
&::before {
background: linear-gradient(90deg, #ff0b, #f00b) border-box;
border: solid var(--border-width) transparent;
/* comment out the mask stuff to see that the text will never be covered */
mask: linear-gradient(90deg, black, black) padding-box, linear-gradient(90deg, white, white) border-box;
-webkit-mask-composite: xor;
mask-composite: exclude;
}
}
/* 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;
}