【发布时间】:2020-11-29 13:52:30
【问题描述】:
我可以使用下面的代码在 div 上使用常规 css 创建我想要的结果。图片贴在屏幕右侧,图片左侧裁剪,因此当您缩小屏幕尺寸时,您仍然可以看到图片中的城堡。
#bgImg{
background-image: url("https://i.stack.imgur.com/pfepb.jpg");
height: 225px;
width: 100%;
background-position: right center;
object-fit: fill;
}
<div id='bgImg'><div>
我无法使用gatsby-background-image 创建相同的结果。图像始终裁剪图像的右侧。
我尝试创建code sandbox,但不幸的是图像没有出现,我不知道为什么
这是我的代码,它裁剪图像的右侧而不是左侧
const bgImgProps: FluidObject = data.bessImg.childImageSharp.fluid
const otherImgProps: FluidObject = data.logoImg.childImageSharp.fluid
<BackgroundImage
Tag="section"
role="img"
className='w-100 h-100'
style={{
backgroundPosition: "right center",
objectFit: "fill"
}}
fluid={bessImgProps}
backgroundColor={`#040e18`}
>
<div className='header-outer-container d-flex justify-content-center'>
<a className='only-gt-md' style={{height: "130px", width: "350px"}} href="/">
<Img
className='w-100 h-100'
fluid={logoImgProps}
fadeIn={false}
loading="eager"
imgStyle={{objectFit: 'contain' }}
></Img>
</a>
</div>
</BackgroundImage>
.header-outer-container{
height: 225px;
}
header{
min-height: 225px;
background-position: right center;
}
这就是它的样子,但我希望从另一侧裁剪图像,以便城堡保持可见,就像上面的普通 css 示例一样。
【问题讨论】:
标签: javascript css reactjs gatsby gatsby-image