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

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

Background color doesnt apply with Tailwind but work with inline style

问题

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

这不会应用背景颜色

<!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">
      <div clas="h-full bg-rose-900">
        <h1 class="text-blue-900 text-center text-4xl">Boards</h1>
        <p>Test</p>
      </div>
    </div>

  </body>
</html>

这会应用背景颜色

<!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">
      <div clas="h-full" style="background-color: rgb(136 19 55);">
        <h1 class="text-blue-900 text-center text-4xl">Boards</h1>
        <p>Test</p>
      </div>
    </div>

  </body>
</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
'''

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

    &lt;div class=&quot;h-full&quot;&gt;
      &lt;div clas=&quot;h-full bg-rose-900&quot;&gt;
        &lt;h1 class=&quot;text-blue-900 text-center text-4xl&quot;&gt;Boards&lt;/h1&gt;
        &lt;p&gt;Test&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;

  &lt;/body&gt;
&lt;/html&gt;

'''

This does apply the background color
'''

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

    &lt;div class=&quot;h-full&quot;&gt;
      &lt;div clas=&quot;h-full&quot; style=&quot;background-color: rgb(136 19 55);&quot;&gt;
        &lt;h1 class=&quot;text-blue-900 text-center text-4xl&quot;&gt;Boards&lt;/h1&gt;
        &lt;p&gt;Test&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;

  &lt;/body&gt;
&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”:

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

Typo of class as @Quentin pointed.

Change

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

to

&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:

确定