I have a div that expands and shrinks depending on the windows size which collapse the images into different rows which I like but how can I prevent the gaps to the right of the screen in the div which is cause by the images not having enough room to fit?
I basically want to center the images horizontally in rows if the images don't have enough room to fit in the previous row which also reduce the div width as well.
This is what I mean visually
This is how I want it to act, This is a photo shop pic keep that in mind
and I still want to keep how if you resize or expand the div to a certain size the images will reduce in less rows which at times can cause a longer row of images for example.
Here is the code
#container{
background-color: gray;
width: 40%;
}
img{
width: 150px;
}
<div id='container'>
<img src='http://www.wallpapereast.com/static/images/MTM3NjEyNzY4MzgyNTU5NDc0.jpg'>
<img src='http://www.wallpapereast.com/static/images/MTM3NjEyNzY4MzgyNTU5NDc0.jpg'>
<img src='http://www.wallpapereast.com/static/images/MTM3NjEyNzY4MzgyNTU5NDc0.jpg'>
<img src='http://www.wallpapereast.com/static/images/MTM3NjEyNzY4MzgyNTU5NDc0.jpg'>
<img src='http://www.wallpapereast.com/static/images/MTM3NjEyNzY4MzgyNTU5NDc0.jpg'>
</div><!--</container>-->