Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Dynamic minmax values inside styled component

I'm trying to make the 250px number inside the minmax function dynamic inside a styled component.

Normally I could just use something like this:

minmax(${props => props.minWidth}, 1fr)

But this breaks instantly and won't even render because it's invalid syntax.

This is my code right now without it being dynamic. Any ideas much appreciated :)

const GridContainer = styled.div`
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  grid-auto-rows: auto;
  grid-gap: 20px;
  width: 100%;
`;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to use template literals.

Below is the code with the correct use of props in the styled component.

const GridContainer = styled.div`
  display: grid;
  grid-template-columns: ${(p) => `repeat(auto-fit, minmax(${p.minWidth}, 1fr))`};
  grid-auto-rows: auto;
  grid-gap: 20px;
  width: 100%;
`;

With default minWidth.

const GridContainer = styled.div`
  display: grid;
  grid-template-columns: ${(p) => `repeat(auto-fit, minmax(${p.minWidth || '250px'}, 1fr))`};
  grid-auto-rows: auto;
  grid-gap: 20px;
  width: 100%;
`;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!