这已被多次询问,但在我的用例中它不起作用。我确定我错过了一些东西。
在功能组件中,我执行以下操作:
const headerImg = {
backgroundImage: `http://localhost:1337${data.service.main_image.url}`
};
然后在 div 中,我执行以下操作:
<div className="bread-cumbs-area" style={headerImg}>
我正在尝试使用 headerImg.backgroundImage 作为背景图像,但它没有显示在我的 div 中。知道我做错了什么吗?
由于您是在 CSS 中设置背景图片,因此您需要使用url()
CSS 函数:
const headerImg = {
backgroundImage: `url('http://localhost:1337${data.service.main_image.url}')`
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句