Advertisement
Udoro

Magical Formula for equal width columns CSS

Aug 11th, 2022 (edited)
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. /* add this to the flex basis of the card
  2. calc((100% / var(--cols)) - (var(--gap) * (var(--cols) - 1)) / var(--cols))
  3. */
  4.  
  5. /* add this to the column gap and row gap of the parent container of the card
  6. var(--gap)
  7. */
  8.  
  9.  
  10. /*add this to the custom CSS of parent container of the card */
  11.  
  12. root {
  13. --gap: 2rem;
  14. --cols: 4;
  15. }
  16.  
  17. @media (max-width:1240px) {
  18. root {
  19. --cols: 3;
  20. }
  21. }
  22.  
  23.  
  24. @media (max-width:960px) {
  25. root {
  26. --cols: 2;
  27. }
  28. }
  29.  
  30. @media (max-width:580px) {
  31. root {
  32. --cols: 1;
  33. }
  34. }
  35.  
  36. /* set the parent container flex wrap to 'wrap', and direction to 'Horizontal(row)'*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement