rachelandrew / cssgrid-ama

Ask me anything about CSS Grid Layout
328 stars 12 forks source link

CSS Grid use of CSS variables #164

Open Illustrissimus-1 opened 3 years ago

Illustrissimus-1 commented 3 years ago

Can CSS variables be used with CSS Grid? In the example below replacing var(--itemsCount) with an integer works OK.

.container { display:grid; grid-gap:10px; grid-template-columns:repeat(var(--itemsCount),43px 43px 43px 43px); grid-auto-rows:75px; }

webcraftsman commented 3 years ago

@Illustrissimus-1

You don't need to repeat 43px. Otherwise, as long as you have defined itemsCount, this should work.

.container { display:grid; grid-gap:10px; grid-template-columns:repeat(var(--itemsCount),43px); grid-auto-rows:75px; }