skip to Main Content
</body>
    <div id="header">
        <div class="container">
            <nav>
                <img src="logo.png" class="logo">
                <ul>
                    <li><a href="#">Home</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Services</a></li>
                    <li><a href="#">Portfolio</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>
            </nav>  
        </div>
    </div>

/css
.container{
    padding: 10px 10%;
}
nav{
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}
nav ul li{
    display: inline-block;
    list-style: none;
    margin: 10px 20px;
}
nav ul li a{
    color: #fff;
    text-decoration: none;
    font-size: 18px;
    position: relative;
}
nav ul li a::after{
    content: '';
    width: 100%;
    height: 3px;
    background: #ff004f;
    position: absolute;
    left: 0;
    bottom: -6px;
    transition: 0.5s;
}
nav ul li a:hover::after{
    width: 100%;

I am making a hover effect for the pages for my portfolio website. Everything else is working but the hovering does not. I added ul and used li as I usually do but it did not work.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed it

    *{
        margin: 0;
        padding: 0;
        font-family: 'Poppins', sans-serif;
        box-sizing: border-box;
    }
    body{
        background: #080808;
        color: #fff;
    }
    #header{
        width: 100%;
        height: 100vh;
        background-image: url(Untitled-2.png) ;
        background-size: cover;
        background-position: center;
    }
    .container{
        padding: 10px 10%;
    }
    nav{
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
    }
    .logo{
        width: 140px;
    }
    nav ul li{
        display: inline-block;
        list-style: none;
        margin: 10px 20px;
    }
    nav ul li a{
        color: #fff;
        text-decoration: none;
        font-size: 18px;
        position: relative;
    }
    nav ul li a::after{
        content: '';
        width: 0%;
        height: 3px;
        background: #ff0;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: -6px;
        transition: 0.5s;
    }
    nav ul li a:hover::after{
        width: 100%;
    }
    nav ul li a:hover {
        color: #ff004f;
    }
    .header-text{
        margin-top: 5%;
        font-size: 30px;
    }
    .header-text h1{
        font-size: 60px;
        margin-top: 20px;
    }
    .header-text h1 span{
        color: #ff004f;
    }
    <!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">
        <title>Personal Portfolio Website - Rishith Dandu</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div id="header">
            <div class="container">
                <nav>
                    <img src="logo.png" class="logo">
                    <ul>
                        <li><a href="#">Home</a></li>
                        <li><a href="#">About</a></li>
                        <li><a href="#">Services</a></li>
                        <li><a href="#">Portfolio</a></li>
                        <li><a href="#">Contact</a></li>
                    </ul>
                </nav>  
                <div class="header-text">
                    <p>UI/UX Designer/Full Stack Devoloper</p>
                    <h1>Hi,I'm <span>Rishith</span><br>Dandu From India</h1>
                </div>
            </div>
        </div>
        <div id="about"></div>
        <div class="container">
            <div class="row">
                <div class="about-col-1"></div>
                <div class="about-col-2"></div>
            </div>
        </div>
    </body>
    </html>


  2. Your nav ul li a::after has width:100% change it to width: 0%;

    Note: I have changed the color of text to make it visible here, add your color to your code.

    Demo

    .container {
      padding: 10px 10%;
    }
    
    nav {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
    }
    
    nav ul li {
      display: inline-block;
      list-style: none;
      margin: 10px 20px;
    }
    
    nav ul li a {
      color: #000;
      text-decoration: none;
      font-size: 18px;
      position: relative;
    }
    
    nav ul li a::after {
      content: '';
      width: 0%;
      height: 3px;
      background: #ff004f;
      position: absolute;
      left: 0;
      bottom: -6px;
      transition: 0.5s;
    }
    
    nav ul li a:hover::after {
      width: 100%;
    }
    </body>
    <div id="header">
      <div class="container">
        <nav>
          <img src="logo.png" class="logo">
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Portfolio</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      </div>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search