Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
how to make tailwind utility class dynamic

I want to create a simple square using tailwind, but I want to make the class dynamic enter image description here

const Design1 = () => {
var h = 10;
var w = 10;
  return (
<div className="bg-[#1a1b1a] h-[100vh] w-[100vw] relative ">
  <BackAndCodeButton />
  <div className="flex h-[100vh] items-center justify-center ">
    <div className={` w-20 h-20 bg-white`}></div>  //This one works 
    <div className={` w-${w} h-${h} bg-white`}></div> //but I want it 
    to work this way
   
  </div>
</div>
 );
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

TailwindCSS doesn't allow you to generate classes dynamically. So when you use the following to generate the class…

`w-${w}`

…TailwindCSS will not pick that up as a valid TailwindCSS class and therefore will not produce the necessary CSS.

Instead, you must include the full name of the class in your source code. You can return the full value like this

function  myFunc(val) {
return "w-"+val ;
}

where val is your size value you are passing like 10 here.

By doing it this way, the entire string for every class is in your source code, so TailwindCSS will know to generate the applicable CSS.

Read more: https://tailwindcss.com/docs/content-configuration#class-detection-in-depth

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda