【发布时间】:2021-01-17 19:10:09
【问题描述】:
我正在尝试为 div 设置背景图像并为其添加颜色叠加层。使用纯 CSS,它看起来像这样:
.backgroundImage {
background-image:
linear-gradient(to bottom, rgba(245, 246, 252, 0.52), rgba(117, 19, 93, 0.73)),
url('../img/backgroundimage.jpg');
width: auto;
height: 40vh;
background-size: cover;
}
但这种 CSS 方法对我不起作用,因为我正在构建的组件将被动态填充(不同的图片、文本内容等)。
我已尝试导入图像并执行与上述 css 相同的操作。不知何故,我可以设置背景图像,但无法让渐变叠加层在我的样式对象内工作。
所以我的下一个方法是将我的 div 包装在另一个 div 中并在那里设置渐变。这似乎也不起作用......
我希望比我聪明的人能回答这个问题...
干杯!
const wrapperPictureBox {
background: "linear-gradient(to bottom, rgba(245, 246, 252, 0.52), rgba(117, 19, 93, 0.73))"
}
const pictureBox = {
background: ` url(${backgroundimage})`,
height: "40vh",
backgroundSize: "cover",
};
<div style={wrapperPictureBox}>
<div style={pictureBox}>text</div>
</div>
【问题讨论】:
标签: css reactjs ionic-framework