Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tailwindcss + Nextjs not working on components only

I can’t really figure out what’s going on. I have a Navbar component that I am importing to certain pages. I’ve super simplified it its just a styled div with a Link inside for now:

/component/Navbar.js

<div className="flex items-center justify-center filter drop-shadow-md bg-white h-20"> 
   <Link className="text-xl font-semibold" href="/">LOGO</Link>
</div>

These classes are appearing in the dom however they are not showing up in styles and are not styling the element as expected. Tailwind appears to be setup correctly as it’s working on the files in the pages folder.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Another confusion fact, if i style the elements with style={{display:"flex"}} it words as you would imagine, and if I add a custom style in the globals.css file it will style the elements. (only if I use normal css rather than @apply the classes)

globals.css

@tailwind base;
@tailwind components;
@tailwind utilities;

.container{
    @apply max-w-[1190px]
}

tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./app/**/*.{js,ts,jsx,tsx}",
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
 
    // Or if using `src` directory:
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

>Solution :

You navbar file is in component folder in tailwind config you have specified only components folder so there is a name differece and tailwind is not going to find your changes in the component folder

change your tailwind config file to this it’ll fix the issue

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./app/**/*.{js,ts,jsx,tsx}",
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./component/**/*.{js,ts,jsx,tsx}",
 
    // Or if using `src` directory:
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

or you can just change your folder name from (component) to (components)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading