如何优雅地使用tailwindcss

tailwindcss存在的意义非常好,可以减少我们对一些基础样式的定义和重复样式设置的冗余,引入tailwind,我们可以多级拼接class,而不用多余去定义class类。
1.首先install tailwind
2.为了使用方便,个人增加如下配置 tailwind.config.js:

module.exports = {
  purge: {
    enable: process.env.NODE_ENV === 'production',
    content: ['./index.html', './src/**/*.{vue,ts,tsx}'],
  },
theme: {
    extend: {
      zIndex: {
        '-1': '-1',
      },
      colors: {
        primary: {
          DEFAULT: '#00a8b2',
          // dark: primaryColorDark,
        },
        secondary: 'var(--color-secondary)',
      },
      spacing: {
        px: '1px',
        1: '0.25rem',
      },
      screens: {
        sm: '576px',
        md: '768px',
        lg: '992px',
        xl: '1200px',
        '2xl': '1600px',
      },
    },
  }
}

3.添加tailwind.css:

:root {
  --color-secondary: #ecc94b;
  /* ... */
}
@tailwind base;
@tailwind components;
@tailwind utilities;

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

4.基础用法

<button class="bg-red-500 hover:bg-red-700 ...">
  Hover me
</button>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容