I have already completed 2 questions regarding the current issue I am facing. However, I have now created a more improved example. Please take a look below. The boxes are being loaded using Angular ng-bind.
Check out the code pen here: http://codepen.io/anon/pen/LRPwZP
Additionally, I have also included the same snippet on Stack Overflow, but please note that resizing the resolution is not possible, so the example may not be as useful.
Please pay attention to the desired behavior:
- Each box has the same width (700px in actual case)
- Box #1 should be positioned at the top left corner
- Box #2 should be placed to the right of Box #1 only if there is enough space
- If there is still space on the screen, Box#3 goes to the right of Box#2
- If there is no longer space available to the right, Box #4 falls below Box #1
- Box #5 is positioned directly below Box #2
- Box #6 goes directly below Box #3
- and so on...
- The boxes are dynamically loaded using Angular ng-bind
I cannot utilize the following options:
(1)
:nth-child(odd) { float: left; }
:nth-child(even) { float: right; }
Reason: It becomes ineffective when more than 2 columns are needed
(2)I know about AngularJS Masonry, however, I prefer not to increase loading time and aim to achieve this using CSS only.
For your information:
- No CSS frameworks are being used
- "Vanilla" JS is occasionally implemented
- AngularJS is heavily utilized
Previous questions on the same issue:
CSS multiple different height float left elements arranged in 2 columns
Flex, AngularJS + Masonry, akoenig/angular-deckgrid and more
Best regards, Chris,