Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind css Grid is not working in Reactjs?

Here is an example of taiwind css grid working properly in HTML : https://play.tailwindcss.com/mU6PzU0sqX

Despites, here is the same example in react, and it seems it does not pass: https://codesandbox.io/s/react-typescript-tailwind-playground-forked-m77pw?file=/src/App.tsx See the not working component in the browser : https://m77pw.csb.app/

Here is the React code :

<div className="App">
      <h1 className="text-red-500">Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
      <div className="grid grid-cols-3 gap-4">
            <div className="border col-span-1">
              1
            </div>
            <div className="border col-span-1">
              2
            </div>
      </div>
</div>
like image 861
Frédéric Lang Avatar asked Oct 21 '25 15:10

Frédéric Lang


2 Answers

Install tailwindcss with npm and make sure you include paths to your templates/components files in tailwind.config.js.

module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
like image 120
Rochdi Belhirch Avatar answered Oct 23 '25 05:10

Rochdi Belhirch


This is also an issue when using VueJS.

It's caused by enabling purge for .vue files.

Solution is to disable purging for .vue files in tailwind.config.js

Perhaps your solution is to disable purging for '.jsx' files except in Production using environment variables.

like image 23
Leon A Avatar answered Oct 23 '25 06:10

Leon A



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!