Can I make a CSS grid with dynamic number of rows or columns?

前端 未结 5 2081
猫巷女王i
猫巷女王i 2020-12-13 08:51

What I wanna do is to make a CSS grid with a dynamic number of cells. For the sake of simplicity, let\'s assume there will always be four cells per row. Can I specify a grid

5条回答
  •  我在风中等你
    2020-12-13 08:59

    You don't need to use repeat. Instead you can just use set a variable --grid-template-columns from your javascript code.

    rootEl.style.setProperty('--grid-template-columns' theGridTemplateColumnsValue)

    theGridTemplateColumnsValue is a string that can also contains other css variables. This way you can have a dynamic number of columns per row.

提交回复
热议问题