You can do this exclusively in CSS. First, as you said .. yes you need the @media type using an external CSS file.
In your CSS file, it might look like this:
@media all { .class #id }
the @media all header is for all screens other than those you specify. It looks like a basic set. For specific, see the following format:
@media screen @media screen and (min-width: 1278px) and (max-width: 1282px) {
Adding identifiers and classes between the two brackets above will contain special rules that will overwrite the rules written in the @media header and take effect only on the screen, whose width is from 1278 to 1282 pixels, so you can see we focus on the screen 1280px x XXX high {12-inch typical low-cost netbook}
The focus on your question is a meta-structure. Suppose we have 4 photos with a size of 400 pixels. The total width is 400 + 400 + 400 + 400 = 1600 pixels. Thus, on a screen with a width of 800 pixels in line 1, only two images will be shown, and the remaining 2 in the second line.
If you applied flex-box without proper html markup, you can move on to the transition where only the right-most element will move to the second line.
From what I understand from your question, you want the transition to be 2 points moving to the second line, as best friends. Something like that:
becomes
The correct markup would be something like this:
<div id="Container"> <div id="Inner"> <div id="Box">Content1</div> <div id="Box">Content2</div> </div> <div id="Inner"> <div id="Box">Content3</div> <div id="Box">Content4</div> </div> </div>
and the correct CSS:
#Container { position: relative; width: auto; min-width: 800px; display: flex; flex-flow: row wrap; } #Inner { position: relative; display: inline-block; } #Box { position: relative; display: block; }
The Flex container is something new with HTML5, so I personally experienced some glitches. You may need to change the position of the #Box to “static” rather than “relative”, and none of them can work (in this case, it should return to static by default, but I saw instances where this is not the case .
I am very sure that what I wrote above is what you need. Greetings.