Tailwind CSS字体尺寸有效,但边距和边界不d。我是否错误地安装了它?

发布于 2025-02-13 19:08:25 字数 2627 浏览 0 评论 0原文

我正在尝试使用Tailwind CSS来设置我的网页 - 整个过程。但是,我的直接目标是在一些输入和按钮上使用边框上一些文本。这是我发现我的尾风配置错误的地方。

因为这种“不起作用”的方式很难诊断出谷歌搜索。我发现了一个结果,建议添加border,因为没有border代码border-brack没有border> border应用本身。但是我做到了,没有任何改变。此外,我可以参见在浏览器中,没有添加边距。

我希望以下代码应为我的按钮提供边框和黑色边框。它没有。

function Button({ label, action }) {
    return (
        <button
            className="border-2 border-black mt-3 text-2xl"
            onClick={() => {
                action();
            }}
        >
            {label}
        </button>
    );
}

export default Button;

这是我的浏览器中存在的代码:&lt; button class =“ border-2 border-2 border-beld-3 text-2xl”&gt; next&lt;/butt&gt;,所以我们知道风格已经到达按钮了。

此外,我看到以来字体已经更新以来,我添加了尾风CSS(因为用自己的tailwind覆盖了默认字体样式), 以下样式 do 工作:

&lt ; H2 className =“ text-2xl”&gt; foo&lt;/h2&gt; //文本实际上更大,证实了Tailwind CSS正在应用某些内容

我必须配置某些东西以使尾风达到我的代码吗?

这是tailwind.config.js在其默认状态下,与/src一起坐在父级目录中:

module.exports = {
    content: ["./src/**/*.{html,js}"],
    theme: {
        extend: {}
    },
    plugins: []
};

运行npx tailwindcss -i ./ src/index.csss.csss -o ./dist/output.css -watch 我确实有&lt; link href =“/dist/output.css” rel =“ stylesheet”&gt;在我的index.html文件中“ rel =“ nofollow noreferrer”>在文档中描述的方式

package.json因为我假设有人会问:

{
  "name": "westland",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^10.4.7",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.5"
  }
}

请帮助&amp;谢谢你!

编辑:测试显示Border-Red-500有效,但Border-Black却没有。

I am trying to style my webpage using tailwind css -- the whole thing. But my immediate goal is to style some text on some inputs and buttons using borders. This is where I discovered that my Tailwind is configured wrong.

Because the way that this "doesn't work" is quite vague its difficult to diagnose with Googling. I found one result that suggested adding border because without a border the code border-black has no border to apply itself to. But I did that and nothing changed. Additionally I can see that in the browser, there is no margin being added.

I expect that the following code should give a margin and black border to my button. It does not.

function Button({ label, action }) {
    return (
        <button
            className="border-2 border-black mt-3 text-2xl"
            onClick={() => {
                action();
            }}
        >
            {label}
        </button>
    );
}

export default Button;

Here is the code as it is present in my browser: <button class="border-2 border-black mt-3 text-2xl">Next</button> so we know the stylings have reached the button.

Additionally I see that the fonts have updated since I added Tailwind CSS (because tailwind overrides default font styling with its own), and the following styling does work:

<h2 className="text-2xl">Foo</h2> // the text is actually bigger, confirming that tailwind css is applying something

Is there something I have to configure to make Tailwind reach my code?

Here is tailwind.config.js in its default state, sitting in the parent directory alongside /src:

module.exports = {
    content: ["./src/**/*.{html,js}"],
    theme: {
        extend: {}
    },
    plugins: []
};

Running npx tailwindcss -i ./src/index.css -o ./dist/output.css --watch doesn't help either and I do have <link href="/dist/output.css" rel="stylesheet"> in my index.html file the way its described in the docs

package.json because I presume someone will ask:

{
  "name": "westland",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.3.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^10.4.7",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.5"
  }
}

Help please & thank you!

edit: Testing reveals border-red-500 works but border-black does not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面如桃花 2025-02-20 19:08:25

如果border-2不起作用,您也可以使用另一种替代方案,即ring-1ring-black

If border-2 is not working, you can also use another alternative ,that is ring-1 and ring-black.

感情洁癖 2025-02-20 19:08:25

在您的tailwind.config.js中使用它

module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Use this in your tailwind.config.js

module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文