Tailwind CSS复选框样式不起作用。

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

Tailwind CSS checkbox styles are not working

问题

cursor-pointer, h-8w-8 是唯一在复选框中起作用的实用程序类。 color 仍然默认为蓝色,在焦点时没有出现环,bg 仍然为白色。

其他示例代码中的元素,如 pdivh1,都可以正常工作。

英文:

I have a checkbox in my Next.js project and after adding some Tailwind utility classes nothing takes effect except changes to width, height and cursor. Color, bg, border, etc. don't work.

        <div className="flex py-4 m-auto w-2/3 justify-between items-start">
          <div className="w-1/7">
            <div className="border-b pb-4">
              <h1 className="mb-2 font-medium">Filter 1</h1>
              <label htmlFor="c1">
                <div className="flex group active:ring-2 ring-black rounded">
                  <input
                    id="c1"
                    type="checkbox"
                    className="rounded-full h-8 w-8 cursor-pointer bg-red-100 border-red-300 text-red-600 focus:ring-red-200"
                  />
                  <p className="pl-2 text-reg cursor-pointer group-hover:underline decoration-solid">
                    Subfilter 1
                  </p>
                </div>
              </label>
            </div>
          </div>
        </div>

cursor-pointer, h-8 and w-8 are the only utility classes that are working in the checkbox. color still defaults to blue, there's no ring appearing on focus, and bg still white.

Others elements in the example code like p, div and h1 are working perfectly.

答案1

得分: 12

在你的 config 文件中添加 tailwindcss/forms

module.exports = {
  theme: {
    extend: {
      // ...
    },
  },
  plugins: [require("@tailwindcss/forms")],
};

你可以在文档GitHub存储库中了解更多信息。

这里有一个在Tailwind Play中的工作示例。

英文:

Add tailwindcss/forms to your config file:

module.exports = {
  theme: {
    extend: {
      // ...
    },
  },
  plugins: [require("@tailwindcss/forms")],
};

You can read more about it in the docs and the GitHub repository.

Here is a working example in Tailwind Play.

答案2

得分: 3

代码部分不要翻译,以下是翻译好的部分:

"The key here is appearance CSS property - set it to none to kinda reset default browser styling"

在这里关键的是 appearance CSS 属性 - 将其设置为 none 以在某种程度上重置默认的浏览器样式

"The appearance CSS property is used to control native appearance of UI controls, that are based on the operating system's theme"

appearance CSS 属性用于控制基于操作系统主题的 UI 控件的本机外观

In Tailwind it is appearance-none utility

在Tailwind中,它是 appearance-none utility

"Use appearance-none to reset any browser-specific styling on an element."

使用 appearance-none 来重置元素上的任何特定于浏览器的样式。

<input
  type="checkbox"
  class="appearance-none ..."
/>

DEMO

英文:

The key here is appearance CSS property - set it to none to kinda reset default browser styling

> The appearance CSS property is used to control native appearance of UI controls, that are based on operating system's theme

In Tailwind it is appearance-none utility

> Use appearance-none to reset any browser specific styling on an element.

&lt;input
  type=&quot;checkbox&quot;
  class=&quot;appearance-none ...&quot;
/&gt;

DEMO

huangapple
  • 本文由 发表于 2023年2月19日 04:54:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75496331.html
匿名

发表评论

匿名网友

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

确定