My ::after hover effect is covering my Anchor text can you help me

Hello everyone i hope you can tell me what is that im doing wrong here.
im trying to make a simple hover effect , but when i hover on the div , the ::AFTER background color covers the text but i want the text to come on top of evrerything , i tried adjusting z-index of the anchor but that didnt help. and now im stuck

*{
    margin: 0;
    padding: 0;
    text-decoration: none;
    list-style: none;
    box-sizing: border-box;

}

body{
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.box{

width: 300px;
height: 150px;
background-color: blueviolet;
cursor: pointer;
}

a{
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    height: 100%;width: 100%;
    color: black;

}

a::after{
    position: absolute;
    content: "";
    width: 100%;
    height: 100%;
    background-color: #000000ad;
    left: 0;
    top: 0;
    z-index: -1;
}

a:hover{
    color: white;
}

a:hover::after{
    z-index: 1;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
    <title>Hover</title>
</head>
<body>
    <div class="box">
        <a href="">Home</a>
    </div>
</body>
</html>

>Solution :

you can fix that by separating the text with spans like

<a href=""><span style="z-index: 100;">Home</span></a>

Leave a Reply