html - 文字颜色不能做成白色

标签 html css reactjs jsx

我有以下 JSX 代码:

  <div style={Object.assign({}, styles.occupyAllScreen, styles.backgroundContainer)}>
    <div styles={styles.overimposingText}>
      <h2 styles={{color: 'white !important'}}>
        Hi everyone!
      </h2>
    </div>
  </div>

使用的样式是这些:

const styles = {
  occupyAllScreen: {
    width: '100%',
    height: '100%'
  },
  backgroundContainer: {
    position: 'relative',
    backgroundColor: 'black',
    textAlign: 'center'
  },
  overimposingText: {
    position: 'absolute',
    color: 'white !important'
  }
};

可以看出,我在包含文本的 h2 和封闭的 div 中都指定了 color: 'white !important' .

但是,组件仍然是这样的:

enter image description here

知道为什么文本不能变成白色吗?

我为它做了一个 fiddle here.

最佳答案

正确的语法

<h2 style={{color: 'white'}}>
      Hi everyone!
    </h2>

关于html - 文字颜色不能做成白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48732711/

相关文章:

javascript - 为什么用户加入房间时视频不显示?

html - 使用 <form> 上传文件不会发送文件

css - 如何在 Angular Material 中定义自定义主题以控制按钮文本的颜色?

javascript - 使用 jQuery 打开 fancybox onclick

css - 悬停样式 '&:hover:{ }' 不适用于 React 组件中的按钮

html - 带有行高的标题中的长标题(多行)

javascript - TypeScript 中的条件泛型类型使用可区分联合

reactjs - 如何为 Form.Item 验证动态设置所需规则

php - 通过 Ajax 进行表单验证

javascript - CSS 打印内容溢出页脚。如何解决?