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 to make display:flex items go to the next line, automatically?

So am new to learning/using the "display: flex" property.

*{
    margin: 10px;
    padding: 0;
    -webkit-margin:0;
    -webkit-padding:0;
}
.container {
    display: flex;
  }
  
  .imagebox {
    position: relative;
    flex: 1;
    margin: 15px;
  }
  
  .imagebox img {
    max-height: 200px;
    max-width: 100%;
    position: absolute;
  }
<div class="container">
        <div class="imagebox">
          <a href="#" class="images">
                  <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
          </a>
        </div>
      
        <div class="imagebox">
          <a href="#" class="images">
            <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
          </a>
        </div>
      
        <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>

          <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>
      </div>

Here are 4 boxes of a certain size but if I insert one more, the size gets smaller as it tries to fit the 5th box in the same line, how to get the 5th box in the next line?

*{
    margin: 10px;
    padding: 0;
    -webkit-margin:0;
    -webkit-padding:0;
}
.container {
    display: flex;
  }
  
  .imagebox {
    position: relative;
    flex: 1;
    margin: 15px;
  }
  
  .imagebox img {
    max-height: 200px;
    max-width: 100%;
    position: absolute;
  }
<div class="container">
        <div class="imagebox">
          <a href="#" class="images">
                  <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
          </a>
        </div>
      
        <div class="imagebox">
          <a href="#" class="images">
            <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
          </a>
        </div>
      
        <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>

          <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>

       <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>
      </div>

I want the images to automatically go on to the next line when it reaches the end of the main container, I have tried reducing the width as well, it didn’t work.
It’s probably something very simple but I can’t really seem to find the way, also am not fully accustomed with all the flexbox properties

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 :

change width of .imagebox {} accordingly

*{
    padding: 0;
    -webkit-margin:0;
    -webkit-padding:0;
}
.container {
    display: flex;
    flex-wrap: wrap;
  }
  
  .imagebox {
    position: relative;
    margin: 15px;
    width: 20%;
  }
  
  .imagebox img {
    max-height: 200px;
    max-width: 100%;
  }
<div class="container">
        <div class="imagebox">
          <a href="#" class="images">
                  <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
          </a>
        </div>
      
        <div class="imagebox">
          <a href="#" class="images">
            <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
          </a>
        </div>
      
        <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>

          <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>

       <div class="imagebox">
            <a href="#" class="images">
              <img class="active" src="https://fakeimg.pl/350x200/000/?text=Image" />
            </a>
          </div>
      </div>
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