背景颜色在Tailwind中不起作用,但在内联样式中有效。

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

Background color doesnt apply with Tailwind but work with inline style

问题

这不太确定我在这里做错了什么。如果我尝试通过Tailwind应用背景颜色,那么颜色不会应用,但如果我尝试通过内联样式来应用,那么它会生效(内联样式从Tailwind文档中复制)。

这不会应用背景颜色

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <script src="https://cdn.tailwindcss.com"></script>
  8. <title>Testing Tailwind</title>
  9. </head>
  10. <body class="h-screen">
  11. <div class="h-full">
  12. <div clas="h-full bg-rose-900">
  13. <h1 class="text-blue-900 text-center text-4xl">Boards</h1>
  14. <p>Test</p>
  15. </div>
  16. </div>
  17. </body>
  18. </html>

这会应用背景颜色

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <script src="https://cdn.tailwindcss.com"></script>
  8. <title>Testing Tailwind</title>
  9. </head>
  10. <body class="h-screen">
  11. <div class="h-full">
  12. <div clas="h-full" style="background-color: rgb(136 19 55);">
  13. <h1 class="text-blue-900 text-center text-4xl">Boards</h1>
  14. <p>Test</p>
  15. </div>
  16. </div>
  17. </body>
  18. </html>

我从Tailwind文档中取的背景颜色是bg-rose-900,对应的CSS属性是background-color: rgb(136 19 55)。希望有人可以指出我做错了什么的正确方向。

英文:

Not quite sure what I am doing wrong here. If I try to apply a background color via Tailwind then it doesn't apply the color but if I try to do it via inline style then it works (inline style copied from Tailwind documentation)

This does not apply the Background color
'''

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html lang=&quot;en&quot;&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;UTF-8&quot;&gt;
  5. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
  6. &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;
  7. &lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
  8. &lt;title&gt;Testing Tailwind&lt;/title&gt;
  9. &lt;/head&gt;
  10. &lt;body class=&quot;h-screen&quot;&gt;
  11. &lt;div class=&quot;h-full&quot;&gt;
  12. &lt;div clas=&quot;h-full bg-rose-900&quot;&gt;
  13. &lt;h1 class=&quot;text-blue-900 text-center text-4xl&quot;&gt;Boards&lt;/h1&gt;
  14. &lt;p&gt;Test&lt;/p&gt;
  15. &lt;/div&gt;
  16. &lt;/div&gt;
  17. &lt;/body&gt;
  18. &lt;/html&gt;

'''

This does apply the background color
'''

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html lang=&quot;en&quot;&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;UTF-8&quot;&gt;
  5. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
  6. &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;
  7. &lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
  8. &lt;title&gt;Testing Tailwind&lt;/title&gt;
  9. &lt;/head&gt;
  10. &lt;body class=&quot;h-screen&quot;&gt;
  11. &lt;div class=&quot;h-full&quot;&gt;
  12. &lt;div clas=&quot;h-full&quot; style=&quot;background-color: rgb(136 19 55);&quot;&gt;
  13. &lt;h1 class=&quot;text-blue-900 text-center text-4xl&quot;&gt;Boards&lt;/h1&gt;
  14. &lt;p&gt;Test&lt;/p&gt;
  15. &lt;/div&gt;
  16. &lt;/div&gt;
  17. &lt;/body&gt;
  18. &lt;/html&gt;

'''

The background color I took from the Tailwind documentation

bg-rose-900 background-color: rgb(136 19 55);
https://tailwindcss.com/docs/background-color

Hoping someone can point me in the correct direction on what I am doing wrong.

答案1

得分: 0

将“clas”更正为“class”:

  1. &lt;div class=&quot;h-full&quot; style=&quot;background-color: rgb(136 19 55);&quot;&gt;
英文:

Typo of class as @Quentin pointed.

Change

  1. &lt;div clas=&quot;h-full&quot; style=&quot;background-color: rgb(136 19 55);&quot;&gt;

to

  1. &lt;div class=&quot;h-full&quot; style=&quot;background-color: rgb(136 19 55);&quot;&gt;

huangapple
  • 本文由 发表于 2023年3月4日 00:18:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75629499.html
匿名

发表评论

匿名网友

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

确定