Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get this flex container to wrap in React?

I’m trying to make a list of cards with images and a short description but I can’t figure out the CSS here. This is iterating through JSON data. I can’t get the flexbox to wrap to the next line. It keeps adding new articles to the first line.

<div className='box'>
{artData.map((data:any, key:string) => {
  return (
    <li key={key} className='article'>
    <div>
    <img  src={data.images[0]}></img>
   </div>
   <br></br>      
   {data.description}</li>);
    })}
</div>
.box {
  display: flex;
  justify-content: space-evenly;
  list-style: none;
  align-items: stretch;
  gap:20px;
  margin: 2%;
  flex-wrap: row wrap;
}

Update: I was missing ‘flex-wrap: wrap;’ Thanks everyone

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Maybe the parent element is positioned absolute hence why the .box class isn’t restricted?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading