You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React+Tailwind项目中div背景不显示问题求助

问题排查与解决
  • 检查自定义颜色配置
    你用到的from-neutral-blue和to-neutral-yellow属于自定义颜色类,必须在tailwind.config.js中提前定义,否则Tailwind会忽略这些类,导致<main>的渐变背景不生效(实际为透明状态)。如果div的背景色和页面默认背景色一致,就会看起来像是没显示。
    配置示例:

    /** @type {import('tailwindcss').Config} */
    module.exports = {
      content: [
        "./src/**/*.{js,jsx,ts,tsx}",
      ],
      theme: {
        extend: {
          colors: {
            'neutral-blue': '#你的蓝色十六进制值',
            'neutral-yellow': '#你的黄色十六进制值',
          },
        },
      },
      plugins: [],
    }
    
  • 验证div样式优先级
    打开浏览器开发者工具,查看div的样式面板,确认background-color属性是否被其他样式覆盖。如果存在样式冲突,可临时添加!important测试(不推荐长期使用,建议排查冲突来源):

    <div className="bg-slate-700 !important w-14 h-14">a</div>
    
  • 确认Tailwind配置加载正常
    检查项目的postcss.config.js和tailwind.config.js是否严格按照官方文档配置,同时确认已安装tailwindcss、postcss、autoprefixer这三个必要依赖,确保Tailwind能正确解析所有类名。

内容的提问来源于stack exchange,提问作者Nathan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 13:33:27