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

Tailwind CSS背景色类不生效但内联样式正常的问题求助

问题根源:HTML属性拼写错误

你遇到的问题是拼写错误——在不生效的代码中,你把HTML的class属性写成了clas(少了最后一个字母s)。这个错误导致浏览器无法识别bg-rose-900这个Tailwind类,所以背景色样式没有被应用。

内联样式能生效是因为它直接写在style属性中,不受clas这个错误属性的影响。

修正后的代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.tailwindcss.com"></script>
    <title>Testing Tailwind</title>
  </head>
  <body class="h-screen">

    <div class="h-full">
      <!-- 修正clas为class -->
      <div class="h-full bg-rose-900">
        <h1 class="text-blue-900 text-center text-4xl">Boards</h1>
        <p>Test</p>
      </div>
    </div>

  </body>
</html>

内容的提问来源于stack exchange,提问作者Mr-DillinG

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 23:00:16