Tailwind CSS未输出背景类。

huangapple go评论60阅读模式
英文:

Tailwind CSS is not outputting classes for the background

问题

Tailwind CSS没有为背景生成类。

当我尝试创建一个简单的类,比如bg-black时,它没有添加到output.css文件中。然而,当我临时添加一些像网格或flex之类的内容时,它会将类添加到输出中。是语法问题、配置文件问题,还是完全不同的问题?如果需要更多代码,请告诉我,提前感谢!

配置文件(tailwind.config.js):

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["./index.html"],
  theme: {
    colors: {
      transparent: "transparent",
      current: "currentColor",

      backgroundpink: {
        DEFAULT: "#faeaf5",
      },
      primarypink: {
        DEFAULT: "#eaa4b1",
      },
      vanilla: {
        DEFAULT: "#f7e6de",
      },
      accentorange: {
        DEFAULT: "#eabaa4",
      }

    },
    extend: {},
  },
  plugins: [],
}

HTML文件(index.html):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body class="bg-black">
    
</body>
</html>

希望这些信息对你有所帮助。

英文:

Tailwind CSS is not generating classes for the background.

When I tried to create a simple class like bg-black, it didn't add it to the output.css file. However, when I would temporarily put something like a grid or flex in there, it would add the class to the output. Is it syntax, the config file, or something else entirely? Let me know if you need more code, and thanks in advance!

CONFIG (tailwind.config.js):

/** @type {import(&#39;tailwindcss&#39;).Config} */
module.exports = {
  content: [&quot;./index.html&quot;],
  theme: {
    colors: {
      transparent: &quot;transparent&quot;,
      current: &quot;currentColor&quot;,

      backgroundpink: {
        DEFAULT: &quot;#faeaf5&quot;,
      },
      primarypink: {
        DEFAULT: &quot;#eaa4b1&quot;,
      },
      vanilla: {
        DEFAULT: &quot;#f7e6de&quot;,
      },
      accentorange: {
        DEFAULT: &quot;#eabaa4&quot;,
      }

    },
    extend: {},
  },
  plugins: [],
}

HTML (index.html):

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;title&gt;Document&lt;/title&gt;
&lt;/head&gt;
&lt;body class=&quot;bg-black&quot;&gt;
    
&lt;/body&gt;
&lt;/html&gt;

答案1

得分: 1

颜色 black 在最终解析的 Tailwind 配置中不存在,因为您通过指定 theme.colors 对象完全覆盖了默认的 Tailwind 颜色。

如果您确实想要完全覆盖默认的 Tailwind 颜色但仍然希望保留 black 作为一种颜色,请将其添加到 theme.colors.black 中:

/** @type {import('tailwindcss').Config} */
module.exports = {
  // …
  theme: {
    colors: {
      // …
      black: '#000',
    },
    extend: {},
  },
  // …
}

否则,如果您希望保留默认的 Tailwind 颜色,同时又定义自己的颜色附加于其中:

/** @type {import('tailwindcss').Config} */
module.exports = {
  // …
  theme: {
    extend: {
      colors: {
        // 这里不严格需要“transparent”和“current”,
        // 因为它们在默认的 Tailwind 颜色调色板中已经存在。
        // transparent: "transparent",
        // current: "currentColor",
        backgroundpink: {
          DEFAULT: "#faeaf5",
        },
        primarypink: {
          DEFAULT: "#eaa4b1",
        },
        vanilla: {
          DEFAULT: "#f7e6de",
        },
        accentorange: {
          DEFAULT: "#eabaa4",
        }
      },
    },
  },
  // …
}
英文:

The color black does not exist in the final resolved Tailwind configuration because you have completely overridden the default Tailwind colors by specifying theme.colors object.

If you did indeed want to completely override the default Tailwind colors but still want black as a color, add it to theme.colors.black:

/** @type {import(&#39;tailwindcss&#39;).Config} */
module.exports = {
  // …
  theme: {
    colors: {
      // …
      black: &#39;#000&#39;,
    },
    extend: {},
  },
  // …
}

Otherwise, if you wanted to keep the default Tailwind colors but define yours in addition:

/** @type {import(&#39;tailwindcss&#39;).Config} */
module.exports = {
  // …
  theme: {
    extend: {
      colors: {
        // `transparent` and `current` aren&#39;t strictly needed here
        // since they are in the default Tailwind color palette.
        // transparent: &quot;transparent&quot;,
        // current: &quot;currentColor&quot;,
        backgroundpink: {
          DEFAULT: &quot;#faeaf5&quot;,
        },
        primarypink: {
          DEFAULT: &quot;#eaa4b1&quot;,
        },
        vanilla: {
          DEFAULT: &quot;#f7e6de&quot;,
        },
        accentorange: {
          DEFAULT: &quot;#eabaa4&quot;,
        }
      },
    },
  },
  // …
}

huangapple
  • 本文由 发表于 2023年5月28日 10:24:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349711.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定