Skip to content

How to use CSS Grid auto-fill and auto-fit with Tailwind CSS? #5541

Answered by simonswiss
martinszeltins asked this question in Help
Discussion options

You must be logged in to vote

Hey @martinszeltins 👋

Two ways you can do this:

1. Extend the gridTemplateColumns object in your Tailwind config

module.exports = {
  theme: {
    extend: {
      gridTemplateColumns: {
        'auto-fill-100': 'repeat(auto-fill, minmax(100px, 1fr))',
        'auto-fit-100': 'repeat(auto-fit, minmax(100px, 1fr))',
      },
    },
  },
}

This will create a grid-cols-auto-fill-100 and grid-cols-auto-fit-100 (but feel free to name them differently in the config!) 👍


2. Inline the grid-template-column definition in a JIT arbitrary value

The grid-cols-* utilities accept arbitrary values when JIT mode it turned on. That means you can do things like this:

grid-cols-[repeat(auto-fill,minmax(100px…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@thompsonmanda08
Comment options

@Mohit-au50
Comment options

@Janaka-Steph
Comment options

@Mohit-au50
Comment options

@thompsonmanda08
Comment options

Answer selected by martinszeltins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
5 participants