Link background and text colors are randomly generated hex strings:
$count = count($links); // $links is an multidimensional array
while ($count > $i) {
$bg[$i] = substr(md5(mt_rand()), 0, 6);
$fg[$i] = strrev($bg[$i]);
$bg[$i] = '#'.$bg[$i];
$fg[$i] = '#'.$fg[$i];
$i++;
}
$maxcols = 4;
if ($count > $maxcols) { $colcount = $maxcols; } else { $colcount = $count; }
$width = 100 / ($colcount);
$widthrepeat = 100 / $width;
$x=0;
while($x < $widthrepeat) {
$widthpropertyvalue = $width.'% '.$widthpropertyvalue;
$x++;
}
// width: 33.333333333333
// widthrepeat: 3
// widthpropertyvalue: 33.333333333333% 33.333333333333% 33.333333333333%
and later, in the CSS:
.gridbox {
display: grid;
grid-template-columns: <? echo $widthpropertyvalue; ?>;
}
.gridblock:last-child {
grid-column: 1 / <? echo $widthrepeat+1; ?>;
}