Search code examples
cssimagehovervisibilityhidden

Make img appear next to navbar link on hover


I have these 3 triangles and each one of them is next to a navbar link. I want to be able to hover over the navbar link and make the triangle appear next to it. So far I cannot get it to appear and I have no clue why. I am new to scss so maybe that is why I am not getting it. I had to use visibility: hidden because if I use display none, it will take away the margins that are a necessity.

 <!--desktop nav-->
        <nav class="navbar-desktop">
            <div class="container">
                <div class="navbar-menu">

                    <div class="nav-items">
                        <img src="./img/neon-pink.png" class="about-bullet">
                        <a id="about-hover" href="about.html">About</a>
                    </div>
                    <div class="nav-items">
                        <img src="./img/neon-pink.png" class="work-bullet">
                        <a id="work-hover" href="work.html">Work</a>
                    </div>
                    <div class="nav-items">
                        <img src="./img/neon-pink.png" class="contact-bullet">
                        <a id="contact-hover" href="#">Contact</a>
                    </div>

                    <!--social-->
                    <div class="social-container">
                        <a target="_blank" href="https://github.com/"><i
                                class="fa-brands fa-github-square"></i></a>
                        <a target="_blank" href="https://www.linkedin.com/"><i
                                class="fa-brands fa-linkedin"></i></a>
                    </div>
                </div>
            </div>
        </nav>


    a {
      font-family: $ff-secondary;
      text-decoration: none;
      color: white;
    }
    
    #header {
      .navbar-desktop {
        .container {
          justify-content: end;
          .navbar-menu {
            display: flex;
            justify-content: flex-end;
            padding-top: 16px;
            font-size: 1.75rem;
    
            .nav-items {
              display: flex;
              align-items: center;
              .about-bullet,
              .work-bullet,
              .contact-bullet {
                width: 24px;
                height: 24px;
                margin-right: 8px;
                transform: rotate(180deg);
                visibility: hidden;
              }
              a {
                margin-left: 0;
                margin-right: 64px;
                text-shadow: 0 0 20px #fff;
              }
            }
            #about-hover:hover .about-bullet {
              visibility: visible;
            }
            .social-container {
              margin-right: 16px;
              display: flex;
              a {
                margin: 0 8px;
              }
              i {
                font-size: 2.15rem;
              }
            }
          }
        }
      }
    }

Solution

  • The IMG-tag is not a child of the #about-hover, so having a hover on it has no effect.

    The hover would need to be on the nav-items.

    a {
      font-family: $ff-secondary;
      text-decoration: none;
      color: #fff;
    }
    
    #header {
      .navbar-desktop {
        .container {
          justify-content: end;
          .navbar-menu {
            display: flex;
            justify-content: flex-end;
            padding-top: 16px;
            font-size: 1.75rem;
    
            .nav-items {
              display: flex;
              align-items: center;
              .about-bullet,
              .work-bullet,
              .contact-bullet {
                width: 24px;
                height: 24px;
                margin-right: 8px;
                transform: rotate(180deg);
                visibility: hidden;
              }
              a {
                margin-left: 0;
                margin-right: 64px;
                text-shadow: 0 0 20px #fff;
              }
              &:hover {
                .about-bullet,
                .work-bullet,
                .contact-bullet {
                  visibility: visible;
                }
              }
            }
            .social-container {
              margin-right: 16px;
              display: flex;
              a {
                margin: 0 8px;
              }
              i {
                font-size: 2.15rem;
              }
            }
          }
        }
      }
    }