【发布时间】:2021-10-13 16:11:43
【问题描述】:
这里从道具中获取图像,我必须将该图像作为特定元素的背景图像。我使用样式组件实现了这一点。但是在我的应用程序中,我们没有在任何地方使用样式化组件,所以我尝试使用内联样式来实现这一点。因为它是动态的,所以我们不能或可能无法将此图像传递给 CSS 文件。
这是我使用样式组件的方法,无论如何要使用内联样式更改它,请帮助我,谢谢
样式化组件
const BannerImage = styled.div`
&::after {
background: url(${(props) => props.image}) no-repeat;
content: '';
background-size: cover !important;
background-position: center center !important;
right: 0;
height: 100%;
position: absolute;
left: 0;
}
@media (min-width: 992px) {
&::after {
right: calc((-1%) - ((100vw - 992px) / 2));
}
}
`;
元素使用了样式化组件
<BannerImage
image={image}
className="col-lg-6 col-md-16 col-sm-12 col-12 h-100 d-flex"
/>
【问题讨论】: