Combining color and typography classes using Tailwind merge is currently not supported

In my custom styling setup, I have created a custom color class called text-green (colors) and a custom typography class called text-card-highlight (utilities), which includes font size and weight attributes. However, when using tailwind-merge, only one of these classes is being applied.

I'm puzzled as to why this is happening since there are no common CSS attributes between the two classes.

Interestingly, everything works perfectly fine when I use the classes without tailwind-merge.

To provide more context, I have integrated the font classes into my tailwind configuration as utilities:

plugin(({ addUtilities, theme }) => {
    addUtilities(
        {
            '.text-card-subheading': {
                fontSize: theme('fontSize.xxs'),
                fontWeight: theme('fontWeight.normal'),
            },
            '@screen md': {
                '.text-card-subheading': {
                    fontSize: theme('fontSize.xs'),
                },
            },
        },
    )
})

Answer №1

(I am the developer behind the tailwind-merge library)

If you are using a personalized Tailwind CSS configuration, it is important to also set up tailwind-merge accordingly. You can find detailed information about configuring tailwind-merge and there is a helpful recipe for configuration with an example in the documentation.

For your specific scenario:

The text-green class does not require additional setup in tailwind-merge and works seamlessly out of the box.

Regarding the text-card-highlight class, it is suggested to deconstruct it into standard Tailwind CSS classes as it could be complex to configure individually in tailwind-merge (especially if multiple similar classes exist). Learn more here

Instead of using the text-card-highlight class directly, consider creating a JavaScript variable containing the standard Tailwind classes in a string for easier reuse. For example:

const textCardHighlightStyles = 'text-base font-medium'

// within your component
twMerge(textCardHighlightStyles, 'text-green')

By following this approach, merging should function smoothly without any issues.

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

AngularJS search box functionality allows users to easily search through a

1 I am looking to develop a search box using AngularJS similar to the one shown in the image. While I am familiar with creating a normal text box, I am unsure of how to incorporate the search icon. Any guidance on how to achieve this would be greatly appr ...

Tips for eliminating repetitiveness in situations such as BEM modifiers

As I delved into using my own adaptation of the BEM methodology, I encountered a roadblock with modifiers for nested elements. The challenge at hand is changing the link color to red when product-desc-name has the mark class. The snippet below illustrat ...

issue with border color staying the same when focusing

I've been struggling with changing the border on focus in my code. Despite trying various methods, nothing seems to be working. Can someone help me figure out what I'm doing wrong? <input type="text" spellcheck="false" data-placement="top" id ...

What is the best way to implement CSS Float in typescript programming?

For a specific purpose, I am passing CSS Float as props. To achieve this, I have to define it in the following way: type Props = { float: ???? } const Component = ({ float }: Props) => {......} What is the most effective approach to accomplish this? ...

Mastering the Art of Resizing Video Controls: A

https://i.stack.imgur.com/jTgap.png https://i.stack.imgur.com/Exf6Y.png On the initial screenshot, the video player displays normal controls. However, on the same website with identical CSS, the second video player shows different control settings. // C ...

Switch the CSS class with an HTML tag

Can someone help me transform this code snippet with Python 3 and Beautiful Soup? <span class="ld-nowrap"> 20th century’s </span> I need to convert it to: <em> 20th century’s </em> Any suggestions on how to achieve t ...

What is the best way to reference a PHP file located outside the same directory as the main PHP file?

My current file structure looks like this: Wamp>www>Newlinks CSS (folder) header.php footer.php Profiles (folder) MainPHPfile.php I'm trying to include the header and footer files into MainPHPfile.php, but it's not working ...

JavaScript providing inaccurate height measurement for an element

Upon loading the page, I am trying to store the height of an element. To achieve this, I have utilized the jQuery "ready" function to establish a callback: var h_top; var h_what; var h_nav; $(".people").ready(function() { h_top = $(".to ...

Instead of retrieving documents, the MongoDB query is returning topology information

I am currently working with MonogDB and NextJS. My goal is to create an endpoint that returns all the users. However, I am encountering a strange response: { "_events": {}, "_eventsCount": 0 } My code for querying the database looks li ...

How to fix the 'MODULE_NOT_FOUND' issue when combining Tailwind CSS with npm and yarn

While trying to incorporate Tailwind CSS into my project using the command "npx tailwindcss init", I ran into an error message: npm ERR! code MODULE_NOT_FOUND npm ERR! Cannot find module './yarn-lock.js'. What steps should be taken to resolve ...

Encountering issues with Nextjs routes not functioning properly after deployment on an Azure App Service Linux Instance

I recently tried to deploy a next.js app on Azure App Service using a Linux instance. I followed the guidelines provided in this helpful article: . The live version of the app can be accessed at as well as . The routes function correctly on Heroku. For ex ...

The dynamic image requirement feature is failing to function in ReactJS/NextJS

{ storedfiles.map(item => { // return <li key={item.id}>{item.imagepath}</li> return ( <div> <li key={item.id}>{item.i ...

Create a smooth scrolling effect for a div with a fixed position

Having trouble scrolling a fixed position div on the page? Are you using this jquery script: $('html, body').animate({ scrollTop: $(".example").offset().top }, 750); I had to set the body overflow property to hidden for another issue. The ...

Next.JS sends a request to the API every time there is a change in

const handleKeyPress = (e) => { if (e.key === "Enter") { fetchRank(); } }; <input onKeyPress={handleKeyPress} /> function fetchRank() { const text = inputText; const splitText = text.split("#"); axios.get(&quo ...

What causes child margins to extend beyond the boundaries of div elements?

Can anyone shed some light on the advantages of CSS behavior that allows a child element's top and bottom margins to extend beyond the boundaries of its block-parent? Check out this fiddle for a straightforward example. The pink div is influenced by ...

What is the solution to fixing the EPERM error that occurs while trying to run npx create-next-app@latest?

When I attempted to run the create app for React, I encountered an error that stated "Aborting installation. Unexpected error. Please report it as a bug: [Error: EPERM: operation not permitted, mkdir 'D:\React\vita'] { errno: -4048, cod ...

Exploring the use of the map function for iterating in a stepper component of

I've been attempting to integrate Redux Form into my stepper component. However, I'm facing an issue where adding form fields results in them being displayed in all three sections. To address this, I started reviewing the code for the stepper. I ...

Tips for creating a smooth transition using cubic bezier curves

In my current project, I have implemented a CSS transition using the cubic bezier timing function with values (0.16, 1, 0.29, 0.99). However, I have encountered an issue where at the end of the animation, the element's velocity is too slow and the in ...

Navigation bar transforms color once a specific scroll position is reached

My website features a sleek navbar fixed to the top of the window. As users scroll past a specific div, the background color of the navbar changes seamlessly. This functionality has been working flawlessly for me thus far. However, upon adding anchor link ...

Hover shows no response

I'm having trouble with my hover effect. I want an element to only be visible when hovered over, but it's not working as expected. I've considered replacing the i tag with an a, and have also tried using both display: none and display: bloc ...