英文:
tailwind classes not working when i transfer through props while working perfecly when i use cdn link of tailwind css
问题
//Button.jsx
import React from 'react';
const Button = (props) => {
let color = props.color || 'blue';
return (
<button className={`px-4 py-2 font-bold text-black bg-${color}-500 rounded-full hover:bg-${color}-700 focus:outline-none focus:shadow-outline`}>
Click
</button>
);
};
export default Button;
// App.jsx
import Button from "./Button";
import './index.css';
function App() {
return (
<div>
<Button >Click me!</Button>
<Button color="red">Click me!</Button>
<Button color="green">Click me!</Button>
</div>
)
}
export default App
这是您提供的代码的中文翻译部分。
英文:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-js -->
//Button.jsx
import React from 'react';
const Button = (props) => {
let color = props.color || 'blue';
return (
<button className={`px-4 py-2 font-bold text-black bg-${color}-500 rounded-full hover:bg-${color}-700 focus:outline-none focus:shadow-outline`}>
Click
</button>
);
};
export default Button;
// App.jsx
import Button from "./Button"
import './index.css'
function App() {
return (
<div>
<Button >Click me!</Button>
<Button color="red">Click me!</Button>
<Button color="green">Click me!</Button>
</div>
)
}
export default App
<!-- end snippet -->
this is a component where i'm transferring background color using props
i don't know what's wrong... same code just when i add cdn link of tailwindcss in html page it work but don't work without cdn.
if i will transfer bg-red-500 whole class as props then it works but if i send only red as props then it doesn't work.
even in inspect page i can see classes but they're not taking effect.
i'm using vite-react.
答案1
得分: 1
你可能忘记了一步,你是否在你的主CSS文件中执行了以下代码:@tailwind base; @tailwind components; @tailwind utilities;
?入门指南还显示了一个额外的步骤:https://tailwindcss.com/docs/installation
英文:
I think your forgetting a step, did you do @tailwind base;
in your main css?
@tailwind components;
@tailwind utilities;
The getting started also shows one more extra step: https://tailwindcss.com/docs/installation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论