[Tailwind] Create Custom Utility Classes in Tailwind

Source: Internet
Author: User
Tags postcss

In this lesson, we learn how to generate custom utility classes in tailwind. We Add new properties to our JavaScript Config object to generate new helper classes to suit our needs.

Update Gulpfile.js:

Const GULP = require ("gulp"= require ("gulp-postcss"= require ("tailwindcss"= {  "./src/styles.css",  "./tailwind.js",  "./"};gulp.task ("CSS", () = {  return  Gulp    . SRC (paths.css)    . Pipe (Postcss ([Tailwindcss (Paths.config ), Require ("Autoprefixer")])    . Pipe (Gulp.dest (Paths.dist));}); Gulp.task ("Default", ["CSS"], () = {  gulp.watch (paths.config, ["CSS"]);});

For example, you want to add some custom margin and padding in tailwind.js file:

margin: {' Auto ': ' Auto ',    ' px ': ' 1px ',    ' 0 ': ' 0 ',    ' 1 ': ' 0.25rem ',    ' 2 ': ' 0.5rem ',    ' 3 ': ' 0.75rem ',    ' 4 ': ' 1rem ',    ' 6 ': ' 1.5rem ',    ' 8 ': ' 2rem ',    ' + ': ' 4rem ',//added' Crazy ': ' 8rem ',//added}, padding: {' px ': ' 1px ',    ' 0 ': ' 0 ',    ' 1 ': ' 0.25rem ',    ' 2 ': ' 0.5rem ',    ' 3 ': ' 0.75rem ',    ' 4 ': ' 1rem ',    ' 6 ': ' 1.5rem ',    ' 8 ': ' 2rem ',    ' + ': ' 4rem ',//added' Crazy ': ' 16rem ',//added},

After run ' Gulp ' command.

Index.html

  <class= "Text-purple          bg-pink-dark          p-crazy mt-crazy"> Hello tailwind! </ H1 >

Checkout more on Docs.

[Tailwind] Create Custom Utility Classes in Tailwind

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.