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

99
Views
Give variable style properties react

I am trying to build a custom progress bar using React. I have a calculated percentage, I want to set as a width of some div element. Currently I tried it using Tailwind CSS:

<div className={"p-1 w-[" + percentage + "%]"}></div>

But it does not work. So how can I apply this kind of variable styling in React?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Assuming you have the needed Tailwind classes, create a variable to store the classes for the progress bar:

const progressBarClasses = `p-1 w-${progress}`

Assign the classes to the div like this:

<div className={progressBarClasses}></div>
about 4 years ago · Juan Pablo Isaza Report

0

You cannot put expressions in plain JSX, you must use the special curly braces syntax to evaluate an expression and it will resolve to a value:

<div className={"p-1 w-[" + percentage + "%]"}></div>
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!