Issues arise with Primeng functionality post-integration of Tailwindcss into the project

I attempted to combine Tailwindcss and Primeng in a project, but once I import Tailwind, the Primeng styles cease to be applied ongoing

Even with using the Tailwind prefix option, the moment Tailwind is imported, the Primeng styles vanish. To eliminate other possibilities, I initiated a new Angular project (Angular version 16) and exclusively installed Tailwindcss and Primeng.

tailwind.config.js

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

angular.json

{
    "assets": [
    "src/favicon.ico",
    "src/assets"
],
"styles": [
    "src/styles.css"
],
"scripts": []
},

style.css

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

@import "primeng/resources/themes/lara-light-blue/theme.css";
@import "primeng/resources/primeng.css";

Within the app component, there are some test divs (Primeng button and Input - Tailwind container with various styles)

If I remove the tailwindcss imports (specifically @tailwind/base) from the style.css, the primeng components display the correct style but the tailwind styles disappear

Answer №1

Make the necessary adjustments to your style.css file:

@import "tailwindcss/base" layer(tailwindcss);
@import "tailwindcss/components" layer(tailwindcss);
@import "tailwindcss/utilities" layer(tailwindcss);
@import "primeng/resources/themes/lara-light-blue/theme.css";
@import "primeng/resources/primeng.css";

I tested it out and it worked perfectly for me!

Answer №2

Make sure to include the following code snippet in your tailwindcss.config.js file:

corePlugins: { preflight: false }

I have tested it out and it works perfectly!

Answer №3

While previous solutions have been suggested, PrimeNG offers a detailed reference on the topic in their documentation:

@layer tailwind-base, primeng, tailwind-utilities;
        
@layer tailwind-base {
    @tailwind base;
}

@layer tailwind-utilities {
    @tailwind components;
    @tailwind utilities;
}

Reordering these layers as shown above will prevent the Tailwind preflight system from overriding PrimeNG styles.

Source:

Answer №4

I tried several solutions recommended in the primeng documentation, but none of them worked for me. It got me thinking why everyone suggests referring to the docs when it comes to using the preflight feature from tailwind ("Tailwind CSS includes a reset utility in base called preflight. If you are using this feature, wrap the base and utilities in separate layers and make sure primeNG layer comes after the base").

Disabling the preflight feature in the configuration caused some classes like borders to stop working.

Even if you follow the accepted solution, some primeng styling is still affected by tailwind (such as the padding of buttons).

To maintain all primeng styles intact, I disabled the preflight feature in the tailwind config and added necessary preflight features for borders (and any other desired features such as removing list styles) in my styles.css:

@import 'primeng/resources/themes/aura-light-blue/theme.css';
@import 'primeng/resources/primeng.css';

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

// preflight borders
*,
::before,
::after {
  border-width: 0;
  border-style: solid;
  border-color: theme('borderColor.DEFAULT', currentColor);
}

In the tailwind.config.js file:

corePlugins: { preflight: false },

If needed, additional preflight rules can be added: https://tailwindcss.com/docs/preflight

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

Typescript: defining index signatures with numerical types in the range of 1 to 3

type X = {[K in '1' | '2']: string} // valid type Y = {[K in 1 | 2]: string} // invalid https://i.sstatic.net/8iBoK.png Could there be a legitimate explanation for this inconsistency? I couldn't find any related problem on github ...

Encountering errors with the index.css file when setting up TailwindCSS in Vite React configuration

As I embarked on setting up my Vite React project, I followed the documentation to configure TailwindCSS. However, when I attempted to import Tailwind CSS in the index.css file, an error message was displayed. The file only included Tailwind CSS imports. H ...

"Exploring the world of Ionic 2: uncovering its public variables

I'm facing an issue with Ionic 2, specifically with Angular. My concern revolves around a variable called "isConnected". I am unable to access it from an internal function within a function as it gives me an error saying "can't define property of ...

Is a Bootstrap 3 Calendar Available?

I am attempting to design a calendar using Bootstrap 3.3.7 that features consistent square dates, similar to this example: https://i.sstatic.net/dYWbj.jpg It is important to me that each date is displayed in a square format. Here is what I have come up w ...

Retrieve JSON Data in Angular 2

I've defined a model with the following structure: export class ExampleData{ id: string; url: string; } When I make a call to a service, it returns the JSON data shown below: [ { "id": "abc", "url": "/path/to/folder" }, { ...

Block Button styles not displaying in IE when set to Full Width

I can't figure out why, but it seems to be functioning properly on every other internet platform except this one. The first picture shows the button in IE, the second contains the code, and the third displays the button in Chrome. https://i.sstatic. ...

Decrease in font size observed after implementing Bootstrap 5

The issue arises when I include the Boostrap CDN link, resulting in a change in font size. I discovered that Bootstrap has a default font size, which is why attempts to adjust it using an external style sheet with !important do not succeed. Interestingly, ...

Verify if the jQuery library has an existing style attribute

I've been working on a script to loop through my form inputs and check for the presence of the style attribute. Despite feeling like I'm close to getting it right, there seems to be an issue with my code. There are actually only 2 inputs with the ...

Tips for displaying the webpage background above a specific div by utilizing a differently shaped div

I designed a webpage with a background image. At the top, I placed a div element (let's call it div_1) set to 50% width which creates a horizontal black bar with 60% opacity. Directly above that, towards the left at 50%, I want another div element (di ...

Trouble with CSS 3 animations arises if dimensions such as width or height are specified

When I apply a width-transition to a div element, the animation works perfectly. However, if I provide both height and width to the same div in CSS, the animation stops working. What could be the issue? On hover, neither color nor animation changes. How c ...

"Stylish hover effect for list items using CSS arrows

I'm struggling with creating a list menu that has a 1px border and spans the entire width. Here is what I have so far (image 1): https://i.stack.imgur.com/y3EDP.png The tricky part is making it so that when the mouse hovers over a menu item, someth ...

Learn how to stay updated on changes to resolved route data in Angular 2 by subscribing

I'm currently facing an issue with a component that fetches data from a route upon loading. The problem I'm encountering is that whenever the data displayed by the component changes, the component does not update automatically unless I manually ...

"Reduce the height and adjust the row spacing of the Vuetify form for a more

I'm currently working on creating a form using vuetify that closely resembles the one shown in this image: https://i.sstatic.net/4h6YM.png After experimenting with vuetify grid and columns, I've managed to achieve something similar to this: http ...

Error message stating 'is not recognized' caused by Angular SharedModule

I have a navbar component that I've organized into a module called 'NavbarModule' so that it can be easily shared. My goal is to use this component in the 'ProductsListComponent'. However, even after properly importing and exportin ...

The elements within the "ng-repeat" directive are not appearing as expected

My application makes a get request using Angular's http service and then loops over the returned data to display an unordered list in the view. However, I am facing an issue where the data is available after the get request but is not being displayed ...

What could be causing this SVG with CSS animation to appear cropped only in Firefox?

The SVG animation in the hero section of this webpage appears to be cropped only on Firefox. Despite trying a jQuery solution to force the size of the SVG to match the window dimensions, the issue persists. Further investigation is needed to resolve why th ...

Bring to the front the div altered by a CSS3 animation

Recently, I encountered an issue with a div card that triggers an animation when clicked. The animation involves the card scaling up larger, but the problem arises as its edges get hidden under other cards. To visualize this, take a look at the screenshot ...

Problem with Primeng multiselect not displaying selected values

I am currently facing an issue with populating options on a p-multiSelect element. The HTML code in question is: <p-multiSelect name="ambits" [options]="scopes$ | async"> </p-multiSelect> The variable scopes$ is defined as follows: publ ...

The border-radius property in Bootstrap buttons causes unwanted white border artifacts to appear

Strange anomalies in the borders of my Bootstrap buttons caught my attention recently. Upon further investigation, I realized that this issue is not linked to my custom styles or theme, as the artifacts can also be seen on the Bootstrap button documentatio ...

Telerik Border RadCheckBox

Is there a way to get rid of the black border that shows up when the checkbox is clicked in Bootstrap 4.4.1? Check out this image for reference ...