I am using Bootstrap5 and VueJS 2 and trying to create a "pinterest-style" cards layout like shown in this screenshot:
The above layout example requires the following HTML markup: [Codesandbox available]
<main>
<div class="container-fluid">
<div class="row">
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<article>
</article>
<article>
</article>
</div>
<div class="col-md-4">
<article>
</article>
<article>
</article>
</div>
<div class="col-md-4">
<article>
</article>
<article>
</article>
</div>
</div>
<aside class="col-md-3 ml-auto">
...sidebar content...
</aside>
</div>
</div>
</main>
Using JavaScript, how can I take the data array and return 3 new arrays with equal amounts of items in each array except for the last array ? This way I can properly scaffold the layout with an output like shown in the above screenshot? So, for example, if I had a source data array of [1,2,3,4,5,6,7,8,9,10,11]
, I would like to return something like [ [1,2,3,4], [5,6,7,8], [9,10,11] ]
I have an initial attempt at this (in VueJS) but I obviously did not do it correctly because although I got the layout sort of to work, the order was wrong and there were gaps beneath some of the cards. I am afraid my JavaScript knowledge is mediocre. My attempt: https://codesandbox.io/s/vue-bootstrap-card-layout-0xjlt?file=/src/App.vue