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

147
Visualizações
Making equal div height even if the browser is resized

I am trying to make all my divs the same height even if the browser is resized. I have 4 icon boxes. each box has an icon, a title, and a description. I want to make all of them same size. that means if the highest height of the icon container div is 100px all icon holder div will be 100px. the following code is working but if I resize the browser some time the height of the container divs is much bigger than the actual height. what I am doing wrong? (Note the resize will only happen screen size above 767px) thanks

 function allSameHeight(sameSec, sameImg, sameTitle, sameDesc) {
        jQuery(sameSec).each(function () {
          let highestImg = 0;
          let highestTitle = 0;
          let highestTxt = 0;
      
          jQuery(sameSec).find(sameImg).each(function () {
              if (jQuery(this).height() > highestImg) {
                highestImg = jQuery(this).height();
              }
            });
          jQuery(sameSec).find(sameTitle).each(function () {
              if (jQuery(this).height() > highestTitle) {
                highestTitle = jQuery(this).height();
              }
            });
      
          jQuery(sameSec).find(sameDesc).each(function () {
              if (jQuery(this).height() > highestTxt) {
                highestTxt = jQuery(this).height();
              }
            });
      
          if (jQuery(window).width() > 768) {
            jQuery(sameSec).find(sameImg).css("min-height", highestImg);
            jQuery(sameSec).find(sameTitle).css("min-height", highestTitle);
            jQuery(sameSec).find(sameDesc).css("min-height", highestTxt);
          } else {
            jQuery(sameSec).find(sameImg).css("min-height", "auto");
            jQuery(sameSec).find(sameTitle).css("min-height", "auto");
            jQuery(sameSec).find(sameDesc).css("min-height", "auto");
          }
        });
      }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Give a class to all four items. I've used myItem for instance.

const setHeights = () => {
  let highestHeight = 0;
  //Loop through all elements and get the highest height
  $('.myItem').each((index, element) => {
    if($(element).outerHeight() > highestHeight) {
      highestHeight = $(element).outerHeight();
    }
  });
  //Set the height of all elements to highest
  $('.myItem').height(highestHeight);
};

$(window).resize(() => {
  //Run each time window is resized
  setHeights();
});
.myItem {
width: 25%;
color: white;
float: right;
}

.one {
background: red;
}

.two {
background: blue;
}

.three {
background: purple;
}

.four {
background: orange;
}

h3 {
word-wrap: break-word;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div>
<button onclick="setHeights()">Make them equal</button>
</div>

<div class="myItem one">
<h3>
aaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaa
aaaaaaaaaa
</h3>
</div>

<div class="myItem two">
<h3>
bbbbbbbb
</h3>
</div>

<div class="myItem three">
<h3>
ccccccccccccccc
ccccccccc
</h3>
</div>

<div class="myItem four">
<h3>
ddddddddddddddd
ddddddddddd
ddddddddddddd
ddddddddddddddd
ddddddddddddddddd
</h3>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

For this case there are multiple approaches, I'll mention the two most common (in my opinion):

  1. https://www.w3schools.com/howto/howto_css_equal_height.asp
  2. Using flexbox: https://moderncss.dev/equal-height-elements-flexbox-vs-grid/
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