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

333
Visualizações
How to hide a div on line break

Is there a css way to hide an element after a line break caused by a window resize? I want a similar behavior of my nav bar like amazon. If you decrease the window size, the nav elements which have a lack of space collapse to a new line, but the elements are collapsing to a background layer so they dont have an impact on the layout anymore and become invisible.

The solution with display:none on specific screen sizes is not the way I want to handle the problem. white-space:nowrap and overflow:hidden also dont solve it correctly, because this method works only letter for letter on links, and not element by element (i.e. div).

As far as I read the amazon code correctly, they solved it with javascript. Im very interested in a "only css way". Has anyone a clue?

My css code is very simple for the nav + elements:

.site-nav {
  position: relative;
  padding: 0;
  text-align: left;
  margin: 0 0 25px 0;

  a {
    padding: 3px 10px;
  }

   a:hover {
   padding: 3px 10px;
   background-color: #e6f2ff;
   color: #000000;
  }
  
  li {
    display: inline-block;
  }

If I add white-space:nowrap and overflow:hidden to .site-nav I get a similar effect, but not the same. By decreasing the window size the letters of the link disappear one by one. But I want the whole <li> element to disappear at once.

BTW: The code is in a liquid file:

    <div class="grid grid--no-gutters grid--table">
               {% if section.settings.align_logo == 'left' %}
        <nav class="grid__item small--hide" id="AccessibleNav" role="navigation">
          {% include 'site-nav' %}
        </nav>
      {% endif %}
    </div>

#########

Update 2: Using only white-space:nowrap without overflow:hidden in the parent div seems to be a good temporary solution since it switches directly to the next smaller media query appearance.

about 4 years ago · Juan Pablo Isaza
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