I want to achieve the following:
- A button made with pure CSS
- Which has a border with rounded corners
- Which will have gradient color for the border and the text when hovered
I managed the following so far:
(Following screenshots are 300% zoomed)
Description:
- A parent (the button itself): has a grey background and a padding [1]
- A box inside the parent: has a white background [2]
- A box inside the box: contains the text and uses background-clip: text for text gradient on hover
The issue is happening between the elements [1] and [2].
[1] is the container with background and padding and border radius. [2] is the inside box with another background and the same border radius as the parent.
The corners are messy, instead of nice.
I cannot just make a real border with the border property because that won't allow me to create the gradient effect on hover.
.boton-contorno {
display: inline-block;
border: none;
outline: none;
padding: 2px;
background-color: var(--gris-fuerte);
color: var(--gris-fuerte);
border-radius: 8px;
text-transform: uppercase;
cursor: pointer;
font-weight: 800;
white-space: pre;
}
.boton-contorno span {
display: inline-block;
background-color: var(--blanco);
padding: 0.5rem 1.3rem;
border-radius: 8px;
pointer-events: none;
}
.boton-contorno span strong {
font-weight: 800;
font-size: 1rem;
pointer-events: none;
}
.boton-contorno:hover {
background: linear-gradient(-45deg, var(--gris-fuerte), var(--morado));
}
.boton-contorno:hover span strong {
background: linear-gradient(-45deg, var(--gris-fuerte), var(--morado));
background-clip: text;
color: transparent;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-moz-background-clip: text;
-moz-text-fill-color: transparent;
}
<a href="#" class="boton-contorno">
<span>
<strong>¡Ve al plan!</strong>
</span>
</a>