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

362
Visualizações
How to hide thoes children elements that exceed the paraent's width in CSS

The parent has red dashed border, and the children elements are filled with blue. It can be implemented by inline-block, float, flex, etc. enter image description here

I want to implement such effect: when the parent's width gets too small to contain the last children element, then the last element will be hidden.
How to implement this with pure CSS or with minimal JavaScript?

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

0

There is a way to do this using max-width, max-height and overflow, like the example below:

.parent {
   max-width: 400px;
   max-height: 60px;
   overflow: hidden;
   border: 1px dashed #ddd;
}

.child {
   width: 100px;
   height: 50px;
   margin: 5px;
   background-color: blue;
   display: inline-block;
   color: white;
   text-align: center;
}
<p>There are 5 items here</p>
<div class="parent">
   <div class="child">1</div>
   <div class="child">2</div>
   <div class="child">3</div>
   <div class="child">4</div>
   <div class="child">5</div>
</div>

And here is another example using flex instead of display: inline block; with max-width, max-height and overflow too

.parent {
  display: flex;
  border: 1px dashed #ccc;
  max-width: 380px;
  max-height: 60px;
  overflow: hidden;
  flex-wrap: wrap;
}

.child {
  background-color: blue;
  width: 100px;
  height: 50px;
  margin: 5px;
}
<pAnother example, using flex, with 5 items too</p>
<div class="parent">
    <div class="child">1</div>
    <div class="child">2</div>
    <div class="child">3</div>
    <div class="child">4</div>
    <div class="child">5</div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Setting the overflow property of the parent container to hidden can do that for you.

about 4 years ago · Juan Pablo Isaza Relatório

0

If your html structure is static, you can try to look into media queries. Otherwise, i'm not sure it would be possible in CSS.

Using overflow: hidden on your parent element will not make the last child desappear until it totaly overflow.

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