The Tailwind preset is generating CSS code, but the webpage is not displaying the intended styles

Can anyone explain why the preset is generating CSS in the output file, but the styles are not displaying in the browser? When I manually write CSS in newstyle.css, it gets outputted to output.css and renders correctly in the browser.

I attempted adding tailwind.preset.js to content:[] in tailwind.config.js, but it didn't make a difference. Removing mode: 'jit' also had no impact on the issue.

Do I need to include something specific in postcss.config.js for this to work properly?

// package.json

{
  "name": "project-tailwind",
  "version": "1.0.0",
  "description": "tailwindcss sandbox",
  "main": "index.js",
  "scripts": {
    "build": "postcss source/newstyle.css -o public/output.css -w"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "autoprefixer": "^10.4.7",
    "postcss": "^8.4.14",
    "postcss-cli": "^10.0.0",
    "tailwindcss": "^3.1.6"
  }
}

// tailwind.config.js

module.exports = {
    mode: 'jit',
    content: [
        './public/index.html',
        './public/**/*.{html,js}'
    ],
    presets: [
        require('./tailwind.preset.js')
    ]
}

// postcss.config.js

const autoprefixer = require('autoprefixer');

module.exports = {
    plugins: {
        tailwindcss: {},
        autoprefixer: {}
    }
}

// tailwind.preset.js

module.exports = {
    mode: 'jit',
      content: [
        './public/index.html',
        './public/**/*.{html,js}'
    ],
    theme: {
      colors: {
        blue: {
          light: '#85d7ff',
          DEFAULT: '#1fb6ff',
          dark: '#009eeb',
        },
        pink: {
          light: '#ff7ce5',
          DEFAULT: '#ff49db',
          dark: '#ff16d1',
        },
        gray: {
          darkest: '#1f2d3d',
          dark: '#3c4858',
          DEFAULT: '#c0ccda',
          light: '#e0e6ed',
          lightest: '#f9fafc',
        }
      },
      fontFamily: {
        sans: ['Graphik', 'sans-serif'],
      },
      extend: {
        flexGrow: {
          2: '2',
          3: '3',
        },
        zIndex: {
          60: '60',
          70: '70',
          80: '80',
          90: '90',
          100: '100',
        },
      }
    }
  }
/* newstyle.css */

.preset {
    @apply font-sans;
    @apply text-pink-dark;
}

a {
    color: chartreuse;
}

/* output.css */

.preset {
    font-family: Graphik, sans-serif;
    --tw-text-opacity: 1;
    color: rgb(255 22 209 / var(--tw-text-opacity));
}

a {
    color: chartreuse;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tailwind Sandbox</title>
    <link rel="stylesheet" href="/public/output.css">
</head>
<body>
    <h1 class="font-sans text-pink-dark">Welcome to the Tailwind 3.1 Sandbox!</h1>
    <h2>These headings utilize custom base directives</h2>
    <h3>The sizes can be freely manipulated from the tailwind.config.js file</h3>
    <div>
        <a href="#">Link to something</a>
    </div>
    
    <!-- More HTML code omitted for brevity -->
    
</body>
</html>

Answer №1

Despite the creation of a personalized preset, it is essential to append the necessary directives to the original stylesheet. For instance, in my simplified example preset, I had to incorporate the @tailwind utilities directive into the newstyle.css file in order to employ the custom utility classes like font-sans and text-pink-dark.

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

Troubleshooting Paths with Angular's NgFor Directive

Within my Angular project, I have implemented a basic ngFor loop to display logo images. Here is a snippet of the code: <div *ngFor="let item of list" class="logo-wrapper"> <div class="customer-logo"> & ...

Utilize JSoup to extract data from HTML div elements

After exploring this platform, I have found answers to most of my queries. Thank you for that! However, I encountered an issue while parsing a file containing Football Stat data. The div tag below appears to have multiple nested elements which are perplex ...

Disabling the click functionality using ng-disabled on an anchor tag is effective, but the tag remains

I'm facing an issue with an anchor tag that I've styled as a download button using Bootstrap's CSS. The problem is even though I have the ng-disabled attribute in the tag, which visually disables the button, it can still be clicked. Here&apo ...

Iterating through the entire table presents a challenge when trying to display multiple values on a single element

I'm facing a challenge in dynamically adding data from an SQL Table to HTML. Here is my loop: @foreach (var item in Model.ModulesSubStages) { <div class="row"> <div class="col-md-6"><a id="courseRed ...

AngularJS - displaying a notification when the array length is empty and customizing the visibility to conceal the default action

I've been working on an Angular project where I display a loading circle that disappears once the content is loaded. This circle is simply a CSS class that I call from my HTML only when the page first loads, like this: Actually, the circle consists o ...

Accessing the observable's value by subscribing to it

There is a defined observable called imageOptions$ in my code: imageOptions$: Observable<BoundImagesToProject[]> = this.imagesService .getBoundImages({ projectId: this.projectId }) .pipe(map((images) => (images.data))); and it is used in the temp ...

Utilizing fibrous in node.js to efficiently fetch data from the request library

I am struggling to efficiently utilize the fibrous library in conjunction with request for obtaining the body of an HTTP request synchronously. However, I have encountered difficulties in managing the flow. In order to address this issue, I created a simp ...

What is the best way to retrieve the UTC value of a specific date and time within a particular time zone using JavaScript?

I want to create a Date object with a specific time: "Midnight in Los Angeles on Christmas 2011". Although I've used moment.js, which is good, and moment-timezone, which is even better, neither the default Date class nor moment constructors allow for ...

Toggling a div updates the content of a different div

I am looking to make the content within <div class="tcw-content"> dynamically change when a different div is clicked. I have little experience with Ajax, so I'm wondering if there are alternative ways to accomplish this using JS/CSS. If anyone h ...

Understanding how to utilize and manipulate this JSON data using JavaScript

In my code, there is a variable that contains the following data: { "Rows": [ { "New":1, "CachedNumberType":0, "Date":1327479615921, "Type":2, "Number":"123456", "Duration ...

Issue with displaying the Bootstrap-select DropDownList

Within my web application, I have a bootstrap-select combobox that I populate with data using an ajax call. Html: <div class="row"> <select id="selectGemeente1" class="selectpicker" data-live-search="true"></select> </div> Ajax ca ...

Exploring the method to find all corresponding keys within deeply nested objects

Within my 'const', I have an array filled with objects. Each object contains a key called 'image' which holds the value for 'url' as illustrated below. const images =[ { "image": { "url& ...

What is the process for creating a button click listener event in Kotlin or JavaScript?

While working in IntelliJ IDEA, I have created a button in my HTML file with an ID. My goal is to change the header tag to say "button clicked" using Kotlin. After searching through kotlinlang.org and other resources, I am struggling to find a simple refe ...

Implementing scrolling functionality within a nested container

I need help with getting a nested container (.widget2) to scroll while still keeping the borders intact. Currently, the inner container is scrolling past the bottom edge of the parent container, and the scrollbar isn't displaying correctly. If you w ...

Counting down in JavaScript until the desired MySQL datetime format is reached

I'm trying to display a countdown of hours and minutes to a date pulled from a MySQL database in the format 2010-09-24 11:30:12. I am not well-versed with dates in JavaScript, so any guidance would be greatly appreciated. Thank you. ...

Switching the class or modifying the style of an element when it is clicked in Vue.js

The process of retrieving data can be quite intricate. I have an array called "tweets" where the data is stored, and each tweet is represented as a card. I am able to successfully change the style of a card when it's clicked using the markTweet functi ...

Transforming CSS styles into Material UI's makeStyles

My CSS styling was originally like this const Root = styled.div` display: flex; flex-direction: row; margin: 0 auto; width: 100%; position: relative; @media (min-width: ${(p) => p.theme.screen.md}) { width: ${(p) => p.theme.screen.md ...

Utilizing MongoDB query for geoLocation with maxDistance parameter

Customer location: customerCoordinates: [83,24] stores: { id:1, location: {coordinates:[85,44]...} maxRadiusDelivery: 2000 //meters }, { id:2, location: {coordinates:[82,34]...} maxRadiusDelivery: 100 //meters } Query: db.wh.find({ 'locati ...

What steps can I take to prevent my menu items from overlapping in the mobile navigation menu?

I am currently working on creating a mobile menu, but I'm facing an issue where the menu items overlap when hovered over. Instead, I want the menu items to move downwards when hovered upon to prevent the text from overlapping. Below is the HTML code ...

JavaScript Execution Sequence: Demystifying the Order of Operations

I am struggling to comprehend the order of execution in the following code snippet. It is a portion of a larger script, but it all begins with $( "#select-overlay" ). function findSelectedMap(mapID) { $.getJSON('maps.json', function (json) { ...