I’m trying to make a button that has a linear gradient only in the text, but when I make the button it loses the backgroud, can anyone help me?
https://codepen.io/caiohaffs/pen/wvXWBOZ
button.default {
width: 154px;
height: 72px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: 24px;
object-fit: contain;
border-style: solid;
border-width: 1px;
border-image-source: linear-gradient(65deg, #ff8d4d 0%, #6d37ff 100%);
border-image-slice: 1;
background-color: #000;
text-transform: uppercase;
color: #fff;
font-size: 16px;
line-height: 1.75;
letter-spacing: 1.28px;
font-weight: 500;
font-family: 'Roboto Condensed';
}
button.default:hover {
background: #FF8D4D;
background: linear-gradient(to right, #FF8D4D 0%, #6d37ff 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<button class="default">Saiba Mais</button>
2
Answers
Add a pseudo element to keep the background color
#000
:The CSS sets the
z-index: -1
to it displays below the parent element and also usespointer-events: none
to avoid the element from interfering with thehover
event.You can use multiple background where you also need two background-clip