首页  >  问答  >  正文

反应自定义按钮悬停样式不起作用

我的 React 项目中有一个按钮,我是这样设置的。

<label style={styles.label}>
    <input style={styles.input} type="file" accept="image/*" onChange={this.onUpload} />
</label>

样式设置是这样的

label : {
    borderRadius: '1vh',
    cursor: 'pointer',
    height: '2.5vh',
    margin: '0.5vh',
    minWidth: '50px',
    fontSize: '1.7vh',
    justifyContent: 'center',
    alignItems: 'center',
    display: 'flex',
    flexDirection: 'row',
    backgroundColor : 'green',
    color           : 'black',
    opacity         : '0.9',
    '&:hover': {
        backgroundColor : 'green',
        color           : 'black',
        opacity         : '1',
    },
},
input : {
    zIndex   : -1,
    position : 'absolute',
    opacity  : 0,
    visibility : 'hidden',
}

当鼠标悬停在标签上时,悬停样式不会激活,我不确定我在这里做错了什么。

P粉434996845P粉434996845376 天前484

全部回复(1)我来回复

  • P粉797004644

    P粉7970046442023-09-12 13:11:59

    您无法使用内联CSS添加悬停(如何我在内联 CSS 中写入“a:hover”?)。为此使用外部 CSS。 React文档中提到了如何添加外部样式表

    回复
    0
  • 取消回复