【发布时间】:2022-01-20 00:48:45
【问题描述】:
我正在使用React.createElement 创建一个按钮:
React.createElement('button', {style: button.key === this.state.customBtnSelected ? customBtnSelected : customBtnUnSelected, onClick: () => {this.handleCustomBtnClick(i)} }, button.label)
所以其中一种 css 样式在 customBtnUnSelected 变量中。
但是如何为 hover 状态添加 css 类? 到目前为止,这不起作用:
const customBtnUnSelected = {
padding: 12,
textAlign: "center",
textDecoration: "none",
display: "inline-block",
fontSize: 12,
cursor: "pointer",
backgroundColor: "#CFD4DA",
border: "1px solid white",
&:hover: {
color: "#fff"
}
};
【问题讨论】:
标签: javascript css reactjs