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

Images aren't moving to next line when resizing window

I have a div containing some images. I want my images to move to next line when images don’t fit within the screen size. But, images just get cut off, they don’t break to next line!

html

<div class="cd">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
      </div>

css

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

.cd {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
  margin-bottom: 5em;
}

.cd img {
  flex: 1;
  max-width: 100%;
  height: auto;
  max-height: 310px;
}

What am I doing wrong?

>Solution :

You have set the flex-wrap property to nowrap. Simply change to wrap and flex will take care to take everything to the next row if it does not fit the current one.

.cd {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 5em;
}

.cd img {
  flex: 1;
  max-width: 100%;
  height: auto;
  max-height: 310px;
}
<div class="cd">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
        <img src="https://mariongrandvincent.github.io/HTML-Personal-website/img-codePen/slider-logo1.png">
      </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