Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
La propiedad flex-grow parece no funcionar correctamente

Tengo un div principal y dos div secundarios bajo el padre. Según tengo entendido, cuando configuro el crecimiento flexible del primer hijo en cero, el ancho de este elemento nunca cambia, pero cuando agrego algo de texto al segundo hijo, el ancho del primer hijo disminuye. ¿Pero por qué?

 document.querySelector('#button').addEventListener('click', function() { document.querySelector('.child2').appendChild(document.createTextNode('This is text. ')); })
 .parent { width: 400px; height: 400px; background-color: #ccc; display: flex; } .child1 { width: 100px; flex-grow: 0; background: red; }
 <button id="button">Add text</button> <div class="parent"> <div class="child1">fdsafa</div> <div class="child2"></div> </div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes razón. flex-grow evita que el ancho cambie si se está expandiendo . Pero si se hace más pequeño no hace nada. Para eso está flex-shrink . Pruebe flex-shrink en el niño.

 document.querySelector('#button').addEventListener('click', function() { document.querySelector('.child2').appendChild(document.createTextNode('This is text. ')); })
 .parent { width: 400px; height: 400px; background-color: #ccc; display: flex; } .child1 { width: 100px; flex-shrink: 0; background: red; }
 <button id="button">Add text</button> <div class="parent"> <div class="child1">fdsafa</div> <div class="child2"></div> </div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!