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: 3 comments 9 replies

Comment options

You must be logged in to vote
9 replies
@Janaka-Steph
Comment options

@mohit2404
Comment options

@thompsonmanda08
Comment options

@MarcosVini9999
Comment options

@mohit2404
Comment options

Answer selected by martinszeltins
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
8 participants