I'm using Vue3 with TailwindCSS and want to create a grid with a dynamic grid-cols-{n} class. I know that TailwindCSS supports up to 12 columns by default but I can't customize the theme because the amount of columns is completely dynamic.
Given the following plain HTML / Js example
const amountOfItemsPerRow = 16;
const container = document.getElementById("container");
for (let i = 0; i < amountOfItemsPerRow; i++) {
const item = document.createElement("div");
item.innerText = i;
container.appendChild(item);
}
container.classList.add(`grid-cols-${amountOfItemsPerRow}`); // this doesn't work if the value is greater than 12
<script src="https://cdn.tailwindcss.com"></script>
<div id="container" class="grid"></div>
This code works fine if amountOfItemsPerRow is smaller or equal than 12, otherwise the CSS is broken.
Do I have to write code to setup plain CSS solving this or is there a dynamic Tailwind solution?
Another approach:
Based on the docs I tried to replace the line
container.classList.add(`grid-cols-${amountOfItemsPerRow}`);
with
container.classList.add(`grid-template-columns:repeat(${amountOfItemsPerRow},minmax(0,1fr))`);
to come up with a "native" approach but that didn't help.