You can use SASS or Flexbox to achieve the result you are looking for. In this case, SASS will create a more bloated CSS file than ideal, but it will use the rules that you set, and Flexbox will be more reliable and easy to use.
HTML
<div class="screen"> <div data-app>asdf1</div> <div data-app>asdf2</div> <div data-app>asdf3</div> <div data-app>asdf4</div> <div data-app>asdf5</div> <div data-app>asdf6</div> <div data-app>asdf7</div> <div data-app>asdf8</div> <div data-app>asdf9</div> <div data-app>asdf10</div> <div data-app>asdf11</div> </div>
Sass
.screen { position: relative; } .screen [data-app] { $height: 180px; $offset: 20%; $blocks_per_row: 5; position: absolute; width: 20%; @for $i from 0 through 20 { $y: floor($i / $blocks_per_row); $x: $i % 5; &:nth-child(
Flexbox
.screen { display: flex; flex-flow: row wrap; justify-content: flex-start; align-content: flex-start; align-items: flex-start; } .screen [data-app] { flex: 0 1 20%; height: 180px; }
As you can see, there is no upper limit to the Flexbox solution, and it is very clean. I hope any of these solutions help you.
source share