I have a seemingly silly issue where I want to have a pseudo-element beneath a button that just has a border, and creates a "shadow" when hovered. However, when I add a border to the pseudo-element, the border itself seems to ignore the z-index property and show through the button.
Here's a JSFiddle of the "issue"
button {
padding: 20px;
position: relative;
z-index: 1;
background: #2c3e50;
color: white;
border: none;
outline: none;
border-radius: 50px;
}
button::after {
position: absolute;
content: '';
inset: 0;
border-radius: 50px;
border: 3px solid #9b59b6;
z-index: -1;
transition: 300ms ease;
}
button:hover::after {
transform: translateX(10px) translateY(10px);
}
<button>
My button
</button>
What I need is for the purple border to "hide" beneath the button and show only on hover. I tried using opacity but that doesn't solve the issue as the border still shows "above" the button. I also tried using box-shadow instead of border but the results are the same.