I am creating a simple CSS Button and having issues with its z-index.
My Code:
body { /* Ignore Body Styling */
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
button {
padding: 0.7em 1em;
font-size: 25px;
text-transform: uppercase;
font-weight: 600;
border: 5px solid #191919;
border-radius: 0;
background-color: rebeccapurple;
color: #fff;
position: relative;
}
button:hover {
cursor: pointer;
transform: translate(-10px, -10px);
}
button::before {
content: "";
position: absolute;
top: 10px;
left: 10px;
width: 100%;
height: 100%;
z-index: -1;
background-color: rgb(147, 103, 190);
}
button:hover::before {
transform: translate(15px, 15px);
z-index: -1;
}
<button>Click Me</button>
Just run the code once and you will understand.
While :hover
, I don't want the ::before
to cover over my main element (<button>
)
Thank You!