【问题标题】:How to override background color in internal CSS with react js如何使用 React js 覆盖内部 CSS 中的背景颜色
【发布时间】:2019-02-01 07:42:47
【问题描述】:

这是我的代码

eventStyleGetter(event, start, end, isSelected) {
      if (event.id == 39) {
            var style = {
                backgroundColor: '#409931',
                borderRadius: '0px',
                opacity: 0.8,
                color: 'red',
                border: '0px',
                display: 'block'
            };

        }

        return {
            style: style
        }

 }

我想更改背景颜色,但它被另一种 CSS 样式覆盖。如何用 react js 覆盖这个背景色。

【问题讨论】:

  • !important 类中的 !important 标志可能是覆盖您的目标样式的标志。也许删除!important
  • 那个重要的关键字会自动出现,这就是问题所在。 @molamk
  • 试试backgroundColor: '#409931 !important',,应该会覆盖其他规则。
  • @ChrisG 我已经尝试过了,但我不会工作。无论如何感谢您的帮助(Y)
  • 是的,react 显然不支持样式对象中的!important。我发现了这个:npmjs.com/package/react-with-important-style

标签: javascript css reactjs react-big-calendar


【解决方案1】:

与其将其作为style 应用,不如动态应用className,使用相同的eventPropGetter 方法。附加了classNames,因此您应用于事件的任何className 都将在默认类之后进行解析,您可以在类定义中使用!important

【讨论】:

  • 旁注:classNames,从你的eventPropGetter 返回,应该是一个字符串,而不是一个对象,所以如果你有多个,它们必须用空格分隔列表(即className: 'custom-style1 blocked-event'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-09
  • 1970-01-01
  • 2021-02-27
  • 1970-01-01
  • 1970-01-01
  • 2014-06-04
相关资源
最近更新 更多