PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

[FIXED] How to resolve Tailwind and Bootstrap conflicts in an Angular project

 November 19, 2022     bootstrap-4, tailwind-css     No comments   

Issue

I am using Tailwind CSS and Bootstrap (ngx-bootstrap) in the same Angular project. For the most part, they play along nicely. However, when it comes to padding and margins, they fight like siblings. I want to use Tailwind for padding because it is consistent. For example, the class p-X is X times 0.25 rem but with bootstrap, it is all over the place. The annoying thing is that Bootstrap puts !important everywhere.

utilities.css comes from Tailwind and _spacing.scss comes from Bootstrap.

padding 3

padding 4

padding 5

Is there a convenient way to solve this?


Solution

The best practice to avoid naming conflicts with Tailwind utility classes is using prefix option on your tailwind.config.js file.

module.exports = {
  prefix: 'tw-',
}

But if you want only to put !important rule for Tailwind classes, and you have already control the order of css code (tailwind classes are the last), you can set the important option to true on the tailwind config file.

module.exports = {
  important: true,
}

Make sur to not override tailwind classes when you're choosing to set the important option only, see What is the order of precedence for CSS?



Answered By - BENMEDDAH Mohamed
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing