Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bee-interactive's avatar

Re-order collection on mobile with CSS Grid and Tailwind

Hi!

Here's what I'm trying to achieve but I'm a bit lost.. I'm looping throug a Eloquent collection and then, in the blade view, construct my grid with TailwindCSS and the grid grid-cols-1 sm:grid-cols-1 layout.

But, on each "line", the two blocs are linked in desktop version but should be re-organized differently on mobile to keep this odd/even order. Is this behaviour possible only with the tailwind framework?

Any help would be appreciated :-)

grid

0 likes
6 replies
bee-interactive's avatar

Hi @bugsysha !

If you look the order of the mobile version, you can see that the number 4 and 8 are reversed to keep the odd/even colors of the tiles. I've tried your approach but doesn't solve the question..

bugsysha's avatar

LOL, by brain just skipped that details like in a misspelled word 🤒

bugsysha's avatar

As a simplest solution I would probably have one div that is visible just for mobile and one just for larger screens. For mobile I would sort items as following:

collect([1,2,3,4,5,6,7,8,9,10])
  ->sortBy(function ($num) {
    return $num % 2 === 0;
  });

// 1,3,5,7,9,2,4,6,8,10
dnd's avatar

Flexbox and order are your friends

Please or to participate in this conversation.