Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you can fix that by separating the text with spans like

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading