记录tailwindcss依赖和rem适配问题
    		       		warning:
    		            这篇文章距离上次修改已过446天,其中的内容可能已经有所变动。
    		        
        		                
                
// 安装tailwindcss依赖
npm install -D tailwindcss postcss autoprefixer
 
// 使用npx执行tailwindcss的初始化命令
npx tailwindcss init -p
 
// 在项目的入口文件(如:src/index.js 或 src/index.ts)中引入tailwindcss样式文件
import './styles/tailwind.css';
 
// 在postcss.config.js文件中配置tailwindcss插件
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}
 
// 在tailwind.config.js文件中配置fontSize的rem适配
module.exports = {
  theme: {
    extend: {
      fontSize: {
        'xs': ['0.75rem', { lineHeight: '1rem' }],
        'sm': ['0.875rem', { lineHeight: '1.25rem' }],
        'base': ['1rem', { lineHeight: '1.5rem' }],
        'lg': ['1.125rem', { lineHeight: '1.75rem' }],
        'xl': ['1.25rem', { lineHeight: '1.75rem' }],
        '2xl': ['1.5rem', { lineHeight: '2rem' }],
        '3xl': ['1.875rem', { lineHeight: '2.25rem' }],
        '4xl': ['2.25rem', { lineHeight: '2.5rem' }],
        '5xl': ['3rem', { lineHeight: '1' }],
        '6xl': ['3.75rem', { lineHeight: '1' }],
        '7xl': ['4.5rem', { lineHeight: '1' }],
        '8xl': ['6.25rem', { lineHeight: '1' }],
        '9xl': ['8rem', { lineHeight: '1' }],
      },
    },
  },
  // 其他配置...
}以上代码示例展示了如何在一个现代的前端项目中安装和配置tailwindcss,并提供了一个基本的rem适配方案。这个过程涵盖了从依赖安装、初始化配置,到rem适配的全过程,对开发者有一定的实用价值。
评论已关闭