配置相关

在 tailwind.config.js 文件的 theme 部分,您可以定义您项目的调色板、类型比例、字体、断点、边框半径值等。

# 屏幕断点

screens 键允许您自定义项目中的响应断点 :

// tailwind.config.js
module.exports = {
  theme: {
    screens: {
      'sm': '640px',
      'md': '768px',
      'lg': '1024px',
      'xl': '1280px',
      '2xl': '1536px',
    }
  }
}

# 定制间距

在您的 tailwind.config.js 文件的 theme 部分使用 spacing 键来定制 Tailwind 的默认间距/大小比例。

// tailwind.config.js
module.exports = {
  theme: {
    spacing: {
      '1': '8px',
      '2': '12px',
      '3': '16px',
      '4': '24px',
      '5': '32px',
      '6': '48px',
    }
  }
}

# 自定义颜色

您可以添加自己的颜色值来建立一个完全自定义的调色板。

// tailwind.config.js
module.exports = {
  theme: {
    colors: {
      transparent: 'transparent',
      current: 'currentColor',
      blue: {
        light: '#85d7ff',
        DEFAULT: '#1fb6ff',
        dark: '#009eeb',
      },
      pink: {
        light: '#ff7ce5',
        DEFAULT: '#ff49db',
        dark: '#ff16d1',
      },
      gray: {
        darkest: '#1f2d3d',
        dark: '#3c4858',
        DEFAULT: '#c0ccda',
        light: '#e0e6ed',
        lightest: '#f9fafc',
      }
    }
  }
}

# 扩展默认颜色

您想扩展默认的调色板,而不是覆盖它,您可以使用您的 tailwind.config.js 文件中的 theme.extend.colors 部分来实现。

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        'regal-blue': '#243c5a',
      }
    }
  }
}

这将生成像 bg-regal-blue 这样的类,除了所有 Tailwind 的默认颜色。
这些扩展是深度合并的,所以如果您想在 Tailwind 的默认颜色中增加一个额外的阴影,您可以这样做:

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        blue: {
          450: '#5F99F7'
        },
      }
    }
  }
}

这将增加像 bg-blue-450 这样的类,而不会失去像 bg-blue-400 或 bg-blue-500 这样的现有的类。