-1

I have done already 2 questions related with the issue I'm having. But here I have created a better example. Please see below. The boxes are being loaded by Angular ng-bind.

Please see the following code pen: http://codepen.io/anon/pen/LRPwZP

As well, I'm including the same snippet into stackoverflow, but be aware that it's not possible to resize the resolution, therefore, the example might not be useful.

It's very important to notice the desired behaviour:

  1. Every box has the same width (of 700px in the real case)
  2. Box #1 is desired to be at the top left.
  3. Box #2 is desired to be at the right of the box #1 only if there's enough space.
  4. Box #3 if still screen has space, goes at the right of box #2.
  5. Now, assuming there's no longer space at the right, of box #3
  6. Box #4, falls at the bottom of box #1.
  7. Box #5, goes directly at the bottom of the box #2.
  8. Box #6, goes directly at the bottom of the box #3.
  9. so on...
  10. Boxes are loaded using angular ng-bind, and are dynamic.

I can't use the following options:

(1)

:nth-child(odd) { float: left; }
:nth-child(even) { float: right; }

Reason: useless and fails when you need more than 2 columns.

(2) I'm aware of AngularJS Masonry, I don't want to increase the loading time, and I want to accomplish this using only CSS.

For references:

  • No CSS frameworks are being use.
  • Pure "Vainilla" JS is being use - occasionally.
  • AngularJS is heavy used.

Previous questions, same issue:

Kind regards, Chris,

Community
  • 1
  • 1
Chris Russo
  • 450
  • 1
  • 7
  • 21

2 Answers2

0

Why not using flex?

ul{
  background-color: #ffeb00;
  list-style: none;
  padding: 20px;
  margin: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-content: space-around;
}
li{
  padding: 35px;
  margin: 5px;
  background-color: #8056ff;
  color: white;
  text-align: center;
  flex-basis: 40px;
}
<ul>
  <li>Box 1</li>
  <li>Box 2</li>
  <li>Box 3</li>
  <li>Box 4</li>
  <li>Box 5</li>
  <li>Box 6</li>
</ul>  
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
0

So, after a few days testing Masonry, Isotope, and a few different angular and JQuery modules... most of them requiring lots of workarounds just to function properly... and after trying as well different ng-directives and modules made by users to make something like masonry in angular, without using it. I found the solution: AngularMaterial. https://material.angularjs.org/latest/layout/options Might be obvious, but takes time to understand what you're looking for sometimes.

Chris Russo
  • 450
  • 1
  • 7
  • 21