How to extend classes of tailwind in nuxt.js?

Member

by ryleigh , in category: HTML & CSS , 3 months ago

How to extend classes of tailwind in nuxt.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by scotty_walker , 3 months ago

@ryleigh 

To extend tailwind classes in Nuxt.js, you can use the extend option in your tailwind.config.js file. Here's how you can do it:

  1. Create a tailwind.config.js file in the root of your Nuxt.js project if you don't already have one.
  2. In the tailwind.config.js file, you can use the extend option to add custom classes or modify existing ones. For example, to add a custom class named .my-custom-class, you can do the following:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module.exports = {
  theme: {
    extend: {
      colors: {
        'custom-color': '#123456',
      },
      fontFamily: {
        sans: ['Inter', 'sans-serif'],
        serif: ['Playfair Display', 'serif'],
      },
      fontSize: {
        '7xl': '5rem',
      },
      // Add custom classes
      extend: {
        // Use utility function to generate classes
        form: {
          'input': 'form-input',
          'label': 'form-label',
        },
      },
    },
  },
};


  1. Save the changes to your tailwind.config.js file.
  2. Restart your Nuxt.js development server for the changes to take effect.


After following these steps, you should be able to use your custom classes and modified tailwind classes in your Nuxt.js project. Remember to refer to the official Tailwind documentation for more options and configurations that you can use to extend tailwind classes.