Consider this elegant solution using ONLY CSS:
To achieve the desired layout, we can implement a set of media queries that specifically target the last item in each row and modify its color accordingly.
While this task may seem daunting, employing a preprocessor like LESS can simplify the process and reduce the chances of errors. By defining variables within the LESS mixin to suit our requirements, we can effortlessly obtain the desired layout. Take a closer look at the implementation below...
CODEPEN (Try resizing to witness it live)
The usage is straightforward - just invoke the LESS mixin as follows:
.box-layout(boxItemList, li, 100px, 120px, 2, 7, 20px);
This mixin takes 7 parameters:
1) Selector for the list
2) Selector for the items
3) Item width
4) Item height
5) Minimum number of columns
6) Maximum number of columns
7) Margin value
You can customize these parameters to fit your specific needs and obtain the desired layout effortlessly
Here's the CSS (LESS) code snippet provided:
.box-layout(@list-selector, @item-selector, @item-width, @item-height, @min-cols, @max-cols, @margin)
{
// mixin content here...
}
.loopingClass (@layout-width, @next-layout-width, @min-cols) {
// additional function logic here...
}
.box-layout(boxItemList, li, 100px, 120px, 2, 7, 20px);