我正在做一个React.js组件,使用TailWind CSS.我想要做的是根据所选的选项更改 Select 元素的背景 colored颜色 .这就是我try 过的:
import { useState } from "react";
export function Options() {
const [selectedColor, setSelectedColor] = useState("");
const handleSelectChange = (e) => {
setSelectedColor(e.target.value);
};
return (
<select
className={`bg-${selectedColor}-200`}
onChange={handleSelectChange}
value={selectedColor}
>
<option value="">Select a color</option>
<option value="red">Red</option>
<option value="yellow">Yellow</option>
</select>
);
}
我知道那些类存在于TailWind css中.那么我错过了什么呢?
我判断了一下是不是我的tailwind 配置有问题,但似乎一切正常.我已经添加了其他样式,它们显示了出来.