Which has a higher priority, custom utility classes or atomic classes in Tailwind CSS?

gikey

I defined a custom class in tailwind.config.js, such as:

module.exports = {
    theme: {
        extend: {
            fontSize: {
                'regular-12': [
                    '12px',
                    {
                        lineHeight: '20px',
                        fontWeight: '400',
                    },
                ],
            }

        },
    },
};

and then use in html:

class="font-bold text-regular-12"

Is the final font-weight bold or normal?

Currently, it appears that the font-weight is set to bold style.

stickyuser

In the CSS that's created, the extended class .text-regular-12 is listed before the class .font-bold.

These two classes have the same specificity, so the deciding factor is their sequence in the CSS file. The classes that appear later will take precedence over those that were defined earlier.

Consequently, the text will end up having a bold font weight because of this order.

You can see this in the example output here: https://play.tailwindcss.com/uPHbxiHakY?file=css

If you want your custom class to override the font-weight you can define it in the css file like so:

@layer utilities {
  .text-regular-12 {
    @apply text-xs/5 font-normal;
  }
}

Demo: https://play.tailwindcss.com/N9PwsW1I75?file=css

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Tailwind CSS convert more of these inline styles to utility classes

Tailwind CSS not loading custom classes on React app

Does Tailwind CSS remove unused custom CSS classes in production?

Tailwind CSS is not outputting classes for the background

Add spacing in between items with css tailwind classes

Using Tailwind opacity classes with CSS variables

How in Tailwind CSS to use classes with arbitrary values

Tailwind css purge removes all dark classes

Color classes of Tailwind CSS not working when appended

Tailwind css classes not showing in Storybook build

Tailwind css 3.0.5 classes is not working with react

Why is my custom Tailwind CSS utility not applying to React elements?

Should CSS utility classes have the !important keyword?

How to create utility color classes in CSS

Disable prettier for Tailwind classes

Aliases for tailwind classes?

header alignment with tailwind classes

Unable to Apply Tailwind CSS Classes in React Component (TypeScript)

Laravel + Tailwind CSS - Classes not available due to being in Variables

React and Tailwind CSS: dynamically generated classes are not being applied

Tailwind CSS classes show up in the DOM, but the styles are not being applied

Is there a way to chain multiple tailwind css classes on a single hover instance?

Singleton and Static Utility classes

Keeping track of utility classes

The role of enumeration in utility classes?

Adding custom media queries to Bootstrap 3 responsive utility classes

emmet selecting custom classes in css

Is there a way to use variable CSS selector which can selectively apply css to html element which has classes which is a variable?

Selecting Element which Has Exact Combinations of Classes