自定义类字体大小在Tailwind CSS中不起作用。

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

Custom class font-size not working in Tailwind CSS

问题

I have defined a custom class called .myclass in the <style> tag with a font-size of 10rem. However, the font size of the h1 element with the .myclass and text-3xl classes is not being set to 10rem as expected. Can someone please explain why this is happening and suggest a solution?

英文:

I have defined a custom class called .myclass in the &lt;style&gt; tag with a font-size of 10rem. However, the font size of the h1 element with the .myclass and text-3xl classes is not being set to 10rem as expected. Can someone please explain why this is happening and suggest a solution?

&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;style&gt;
    .myclass{
        font-size: 10rem;
    }
&lt;/style&gt;
&lt;body&gt;
  &lt;h1 class=&quot;myclass text-3xl font-bold underline&quot;&gt;
    Hello world!
  &lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;

I expected the h1 element with both the .myclass and text-3xl classes to have a font size of 10rem. However, the font size of the h1 element was not being set to 10rem as expected, and I was unsure why this was happening.

答案1

得分: 1

选项1: 移除.text-3xl类。文本大小将完全依赖于.myclass类。

选项2: 你可以修改Tailwind的配置,将.text-3xl类设置为10rem

module.exports = {
  theme: {
    extend: {
      fontSize: {
        '3xl': '10rem',
      },
    },
  },
  variants: {},
  plugins: [],
}
英文:

Option 1: Remove .text-3xl class. The text-size will be fully rely on .myclass class.

Option 2: You can change the configuration of Tailwind to use 10rem for the .text-3xl class.

module.exports = {
  theme: {
    extend: {
      fontSize: {
        &#39;3xl&#39;: &#39;10rem&#39;,
      },
    },
  },
  variants: {},
  plugins: [],
}

答案2

得分: 1

将此脚本添加到Head或Body标签中:

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

<!-- language: lang-js -->
<script>
    tailwind.config = {
      theme: {
        extend: {
          fontSize: {
            '3xl': '10rem',
          }
        }
      }
    }
</script>

<!-- end snippet -->
英文:

Add this script in Head or Body tag

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

<!-- language: lang-js -->

&lt;script&gt;
    tailwind.config = {
      theme: {
        extend: {
          fontSize: {
            &#39;3xl&#39;: &#39;10rem&#39;,
          }
        }
      }
    }
&lt;/script&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月7日 15:48:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192748.html
匿名

发表评论

匿名网友

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

确定