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

155
Visualizações
How to reset display on a div after changing device size

This is my code and it's horizontal on desktop screen and on phone it's vertical and x button(closebtn) is only on phone displayed and closes the menu bar. How do I automatically display it again, after resizing the page to desktop size?

function oty() {
  document.getElementById("tab").style.display = "none";
}
<div class="icon-bar" id="tab">
  <button class="closebtn" onclick="oty()">X</button>
  <button class="tablink">Home</button>
  <button class="tablink">News</button>
  <button class="tablink">Contact</button>
  <button class="tablink">About</button>
    </div>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

RECOMMENDED: Stick to CSS @media

You can easily add media queries that determine a display of any given element based on viewport size, which is the foundation of responsive design anyways. In your case, keeping the markup as-is, the CSS could be something like...

@media screen and (max-width: 1024px) { // Adjust the break-point size as needed
  #tab {
    display: none;
  }
}

Not recommended: listen for resize event and check the viewport size

While I'd strongly advise against using JavaScript for something CSS is built for, it is possible with JavaScript. Try something like following.

  1. Add a resize event listener to window: (e.g. window.addEventListener('resize', handleResize))
  2. Write a function that toggles your tab element's visibility.
  3. Consider adding a throttle handler to prevent over-firing the events.
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