What is the process for adding tailwind CSS via npm?

Before, I was including Tailwind using a CDN. Now, I have installed it with npm and all three .css files are included, but the styles are not appearing in my HTML document.

Here is the directory structure and a link to style.css

The content of tailwind.config.js looks like this:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

The package.json includes Tailwind CSS version 3.3.3.

All paths to the .css files for Tailwind are correct (base, components, utilities) and I can see successful requests in the network tabs.

I have checked links, paths, package.json, and tailwind.config.js files, everything appears to be in order. Why are the styles still not being applied? Note that I am using simple CSS and not SCSS/SASS.

Answer №1

To get started, follow these steps:

npm install npm install -D tailwindcss postcss autoprefixer vite

In your package.json file:

scripts: {
 "start": "vite",
 "build": "vite build"
}

Your custom tailwind.config.js configuration should look like this:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["*"],
  theme: {
    extend: {},
  },
  plugins: [],
}

Don't forget to link your stylesheet by adding the following line to your HTML file:

<link href="./style.css" rel="stylesheet" >

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to make a unique custom tooltip without using jQuery by utilizing the title attribute

I am looking to implement a tooltip similar to the one shown in the image. The value in the title tag is dynamic and fetched from the controller. https://i.sstatic.net/C2v3D.png Below is the code snippet of my table: <table border="1" cellpadding="10" ...

Facing difficulties in setting up ionic 3 project

I attempted to initialize an ionic v2 project using the following command: sudo ionic start demoApp blank --V2 However, upon running this command on my iMac, I encountered the error displayed below in the command line: npm WARN deprecated <a href="/c ...

Access NodeJS libraries from different directories instead of the default "node_modules" folder without relying on relative paths

In my NodeJS project, I have two folders for libraries - one named "node_modules" which contains publicly available packages, and another called "somename_modules" where we keep proprietary libraries. It's common knowledge that when we use "import" o ...

Rendering the navbar based on conditions

I am currently in the process of finding a way to dynamically change the state of a button based on whether I am on a particular page or not. Here is the code for my navbar: import { Fragment } from 'react' import { Disclosure, Menu, Transition ...

Checking the opacity with an if/else statement, then adding a class without removing the existing class

This function is designed to check the opacity of the header, which fades out as a user scrolls down. If the opacity is less than 1, it disables clickability by adding the class "headerclickoff". However, there seems to be an issue with removing the clas ...

Ways to implement logging in an NPM package without the need for a specific logging library

Currently, I am in the process of developing a company npm package using TypeScript and transferring existing code to it. Within the existing code, there are instances of console.log, console.warn, and console.error statements, as shown below: try { c ...

Why isn't my CSS float behaving as I anticipated?

I'm currently working on a website and facing an issue. The CSS Float property is not behaving as expected. Here is my HTML Code: <div class="slider-menu"> <div class="slider-box"> <img src="agac.jpg"> & ...

To access the link, simply click once if there is no child menu. However, if there is a child menu attached, be sure to click

I am working on a mobile menu that is designed to slide out when clicked. Currently, the parent pages are displayed by default. I want to implement functionality where if a parent page has child pages, clicking on it will slide down the sub menu. If click ...

Package.json failing to enable NodeJS unsafe-perm functionality

Attempting to execute a npm install command with a preinstall script in my package.json. Despite being aware of it being considered an antipattern, I need to run certain scripts as root. The approach works when adding a .npmrc file with the content unsafe ...

Dynamic banner featuring animated text, automatically resizing divs based on width while maintaining body width

Currently, I am working on creating a banner with moving text. While I have managed to come up with a solution for implementing this effect, there are two significant issues that I am facing. The width values in pixels need to be manually adjusted based ...

Disallowing the usage of npm unpublish on a user's device

Hi there, I'm curious to learn about the possibility of implementing a specific npm configuration. Would it be possible to activate npm publish? Is there a way to deactivate npm unpublish --force [IDEAL]? Can all npm unpublish commands be disabled a ...

Trouble getting CSS to load in Webpack

I'm having some trouble setting up Webpack for the first time and I think I might be overlooking something. My goal is to use Webpack's ExtractTextPlugin to generate a CSS file in the "dist" folder, but it seems that Webpack isn't recognizi ...

No updates are appearing on Github despite a significant push

Here are the commands I used to update my web portfolio: git init git remote add origin "GITHUB LINK" git add . git commit -m "VERSION 0.0.0.0" git push --set-upstream origin master || git push origin Despite running these commands, t ...

Content obscuring dropdown menu

I am currently working on a screen design that resembles the following: return ( <SafeAreaView> <View style={styles.container}> <View style={styles.topContainer}> <View style={styles.searchFieldContainer}> ...

The command npm start is failing to launch any React application

I recently set up a new react app using the `create-react-app` command, but when I tried running `npm start`, nothing happened and there were no errors in the console. Here are the troubleshooting steps I have taken so far: I attempted to remove the no ...

Issues occur with Google visualization when the screen is resized

When I resize the browser, an error code google-visualization-errors-8 appears in my Google chart's CSS. https://i.stack.imgur.com/4LX1C.png What could be causing this error to occur? Note: I am redrawing the graph every time the screen is resized. ...

Trouble aligning a div at the center within another div using margin auto

I am facing an issue with centering a div horizontally inside another div. Here is my HTML code: .block { padding: 0px 20px; max-width: 820px; margin: 0 auto; background-color: #ff0; } .container { margin: 0 auto; display: inline-block; bac ...

Hide only the table that is being clicked on, not all tables

Essentially, I am using document.querySelectorAll() to retrieve an array of div elements. In my function, handleClick(), each time the button is clicked, I want to hide the table associated with that specific button. This is the current situation: https:/ ...

Homebrew on Mac - updating Node version does not automatically update NPM version

Can anyone help me with switching Node and NPM versions on my Mac using Homebrew? Currently, I am running Node/NPM 8.2.1/5.3.0, but I want to switch to 6.11.2/3.10.10 as per the documentation. I tried the following commands: $ brew install node@6 $ brew ...

Ways to conceal a child div element without using any specific ID reference

I encountered an issue where I need to conceal all divs within a parent div except the first one. The challenge is that these divs do not possess any unique identifiers. Is there a way to achieve this task using CSS or pure JavaScript? <div role="list ...