内部元素的样式为什么在Tailwind中不生效?

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

Why inner element's style doesn't apply in tailwind?

问题





Document

Hello

英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&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;link rel=&quot;stylesheet&quot; href=&quot;head.css&quot;&gt;
    
&lt;/head&gt;
&lt;body&gt;
    &lt;div class=&quot;grid grid-cols-10&quot;&gt;
        &lt;div class=&quot;col-start-1 col-end-3 bg-slate-600 h-screen&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;col-span-8&quot;&gt;
            &lt;div class=&quot;p-4 bg-slate-400 m-4 h-screen&quot;&gt;
                &lt;div class=&quot;bg-yellow-100 m-4 &quot;&gt;Hello&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        
    &lt;/div&gt;

&lt;/body&gt;

<!-- end snippet -->

I Need to add header in gray section but effect doesn't apply there! Yellow background doesn't appear, only text is shownImage with error
It works fine if in include

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;

<!-- end snippet -->

but not with

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;link rel=&quot;stylesheet&quot; href=&quot;head.css&quot;&gt;

<!-- end snippet -->

(using tailwind CLI)

答案1

得分: 1

你可能没有将Tailwind添加到你的项目中。上面的代码按预期工作。你只需在<head>中添加以下代码:

<script src="https://cdn.tailwindcss.com"></script>

请参考下面的代码片段:

<!doctype html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.tailwindcss.com"></script>
</head>

<body>
  <div class="grid grid-cols-10">
    <div class="col-start-1 col-end-3 bg-slate-600 h-screen"></div>
    <div class="col-span-8">
      <div class="p-4 bg-slate-400 m-4 h-screen">
        <div class="bg-yellow-100 m-4 ">Hello</div>
      </div>
    </div>
  </div>
</body>

</html>

希望这可以帮助你。

英文:

You probably didn't include Tailwind into your project. The code above works as expected. You just need to add &lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt; inside &lt;head&gt;.

See the snippet below.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;!doctype html&gt;
&lt;html&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;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;div class=&quot;grid grid-cols-10&quot;&gt;
    &lt;div class=&quot;col-start-1 col-end-3 bg-slate-600 h-screen&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;col-span-8&quot;&gt;
      &lt;div class=&quot;p-4 bg-slate-400 m-4 h-screen&quot;&gt;
        &lt;div class=&quot;bg-yellow-100 m-4 &quot;&gt;Hello&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/body&gt;

&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年4月13日 19:05:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004685.html
匿名

发表评论

匿名网友

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

确定