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

209
Visualizações
CSS display none removes the element, but leaves its occupied space

In my chart, I would like to remove some of the legend items based on a condition and I am using CSS, display none, from JS controller. Removing works fine, however, a blank space is left at the element's occupied space. Why?

As this HTML is generated dynamically, I am presenting a screenshot from the front-end, in which display: none is highlighted. I attempted to edit tags, play with CSS, in the browser, but nothing helped. The blank space remains still.

enter image description here

And here is the JS controller section that hides the item, but I think the issue is in HTML/CSS. Any help is appreciated.

chart: {
    //.....................................

    callback: function (chart) {


         var legendItems = document.getElementsByClassName('nv-series');

         for (var x = 0; x < legendItems.length; x++) {
                                                
             var legendItem = legendItems[x];
             var content = legendItem.textContent.trim();

             if (content.indexOf('Item 3') !== -1 || content.indexOf('Item 7') !== -1) {
                                 
                 legendItem.style.display = 'none';

              }
          }

     }
}
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The blank space is because the other elements are being transformed to be offset by a certain amount, and that amount stays the same even if one element is hidden.

So when you hide one element, either loop through all of the elements that follow it and manually subtract the width of the hidden element from the translate-x amount, or make another way of listing the elements side by side without using the transform property.

about 4 years ago · Santiago Trujillo 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