反应背景图像叠加不透明度

时间:2018-04-22 04:42:19

标签: reactjs css3 stylesheet

找不到如何在reactjs中设置背景图片覆盖不透明度的方法,我正在尝试做类似的事情。

风格

const styles={ 
 header:{ 
 background: 'rgba(0, 0, 0, 0.5)', 
 backgroundImage:url(${background}),
 height: '100vh', 
 backgroundPosition:'center', 
 backgroundRepeat: 'no-repeat',
 backgroundSize: 'cover' 
 }
}

JSX

<div style={styles.header}>
      <div>
        Portfolio
      </div>
</div>

1 个答案:

答案 0 :(得分:2)

您应该为内部块添加样式并在那里设置背景颜色。 另外,我建议您使用字符串模板为assert样式创建有效值。

我们在这里:

backgroundImage

示例代码here