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

180
Visualizações
How to resize list elements to fit parent width

I noticed in Wikipedia https://en.wikipedia.org/wiki/Hercules#Modern_era that there is a gallery of unsorted lists that always resize themselves to fit the maximum width based on how many elements there are in a row. You can see this if you resize your browser window. After an image jumps to a new row it re-calculates the width of the remaining images to then fill out the full width of the row again.

I'm guessing this is done through javascript or jquery (instead of CSS) however I don't know how would someone get the number of elements that are currently in a single row to recalculate the width for each element in this case.

Is there a simple solution to this?

Below is the list implementation of this without the resizing:

ul{
  border: 1px solid #000;
  background-color: #eee;
  display: block;
  text-align: center;
  list-style-type: none;
  padding: 0;
}
li{
  padding-left: 0;
  display: inline-block;
  margin: 5px;
  vertical-align: left;
}

.block{
  width: 40px;
  height: 60px;
  background-color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
  <li> <div class="block"></div> </li>
  <li> <div class="block"></div> </li>
  <li> <div class="block"></div> </li>
  <li> <div class="block"></div> </li>
  <li> <div class="block"></div> </li>
  <li> <div class="block"></div> </li>
</ul>

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

0

You need to use grid display for that:

ul {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
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