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

302
Visualizações
How can i create dynamic grid layout which width changed dynamically as per their content length and adjust their positions?

I want to create a dynamic grid layout of 2 columns and any number of rows there. in this grid, I put the element's name. as per the element name's length the width of the grid going to adjust. like if the element length is less than 13 then element adjust in grid column ('1 / 2') or ('2 / 3') otherwise it take width ('1 / 3') of grid. and there is a condition is that in the grid layout there is no one going to blank.

I tried for that and I did the code but in some cases, there are some blank spaces. So try and share the optimum solution with me.

  const setGrid = (a) => {
  a.forEach((obj) => {
    if (obj.innerText.length > 13) {
      const parent = obj.parentNode;
      if (parent) {
        parent.style.gridColumn = "1 / 3";
      }
      const parentLeft = parent.previousSibling;
      if (parentLeft) {
        if (parentLeft.innerText.length < 13) {
          const parentLeftL = parentLeft.previousSibling;
          if (parentLeftL) {
            if (parentLeftL.innerText.length < 13) {
              const parentLeftLL = parentLeftL.previousSibling;
              if (parentLeftLL) {
                if (parentLeftLL.innerText.length < 13) {
                  parentLeftLL.style.gridColumn = "1/2";
                  parentLeftL.style.gridColumn = "2/3";
                  parentLeft.style.gridColumn = "1/3";
                } else {
                  parentLeftLL.style.gridColumn = "1/3";
                  parentLeftL.style.gridColumn = "1/2";
                  parentLeft.style.gridColumn = "2/3";
                }
              } else {
                parentLeftL.style.gridColumn = "1/2";
                parentLeft.style.gridColumn = "2/3";
              }
            } else {
              parentLeftL.style.gridColumn = "1/3";
              parentLeft.style.gridColumn = "1/3";
            }
          } else {
            parentLeft.style.gridColumn = "1/3";
          }
        } else {
          parentLeft.style.gridColumn = "1/3";
        }
      }
    }
  });
};

I want this kind of output

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