If I have a container with a width of 1000 pixels filled with elements, all of which are 200 pixels wide. How can I calculate the tile / column position?
To explain in more detail:

The only variables that I will know are the width of the container (1200 pixels in the above example), the width of the element (200 pixels above) and the index of objects (starting from 1).
Given only the information above, how can I calculate the row and column of a cell by entering its index using javascript.
eg. Given the maximum values ββfor line in line 6 (which can be easily calculated from the width and width of the container), I need to be able to calculate this position number 7 . in row row 2, column 1 .
The width of the container and the element can not always be divided exactly so that the equation should take into account any extra spaces at the end of each line and, naturally, transfer the elements to the next line, as it would in the html float layout.
Thank you in advance
EDIT:
I managed to get the string pretty accurately by doing the following:
var itemsperrow = Math.floor(containerwidth/ itemwidth); var column = Math.ceil(itemindex / itemsperrow )
This is with an index of elements starting at 1, not 0;
source share