Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
nav links do not hide when ul is at 0%

I am trying to create a side nav with HTML, CSS, and Javascript. I was able to create the function in order to open and close the navigation. The issue I am running into which I did not notice until I added the background image is that the links still pop out even though the navigation is closed. I tried display: none; on both the li and links. The results are that no links appear and if I try visibility only the Home link appears. here is my code

<nav>
            <p class="brand">DreamJob</p>
        
        <div class="burger">
            <div class="line"></div>
        </div>
        <ul class="ul-one">
            <li class="li-one"><a href="#" class="links-one">Home</a></li>
            <li class="li-one"><a href="#" class="links-one">About</a></li>
            <li class="li-one"><a href="#" class="links-one">Contact</a></li>
            <li class="li-one"><a href="#" class="links-one">Feedback</a></li>
            <li class="li-one"><a href="#" class="links-one">Sign up</a></li>
            <li class="li-one"><a href="#" class="links-one">Sign in</a></li>
        </ul>
    </nav>

nav .ul-one {
  position: absolute;
  right: 0;
  top: 90px;
  background-color: #111;
  width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  transition: 0.5s ease-in-out;
}

nav .ul-one .li-one {
  margin: 10px 0px 10px 0px;
  z-index: 200;
}

nav .ul-one .li-one .links-one {
  color: #fff;
  font-size: 16px;
  font-family: karma;
  text-decoration: none;
  display: none;
}

function nav () {
    let burger = document.querySelector(".burger");
    let ul = document.querySelector("ul-one");
    let links = document.querySelector(".links-one");
    let openNav = false;
    burger.addEventListener("click", ()  =>  {
if (!openNav) {
   document.querySelector(".ul-one").style.width = "40%";
   document.querySelector(".links-one").style.display ="block";
   openNav = true;
}else {
    document.querySelector(".ul-one").style.width = "0";
    document.querySelector(".links-one").style.display ="none";
    openNav = false;
}
    });
}
nav();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

your problem is with the querySelector function. according to https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector querySelector returns first element that matched with the provided selector not all of them.

you have to use querySelectorAll or getElementsByClassName and change style for every element in elements list.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda