reactjs - 使用 Material-UI 的 ButtonBase 和 gatsby-background-image
问题描述
我正在尝试实现 Material-UI复杂按钮演示,但使用 gatsby-background-image 提供图像,但无论我尝试做什么,我似乎都无法正确输入图像,这是我的最大努力到目前为止,用于替换 classes.imageSrc 跨度:
<BackgroundImage
Tag="span"
className={classes.imageSrc}
fluid={post.frontmatter.featuredImage.childImageSharp.fluid}
backgroundColor={`#040e18`}
/>
编辑:这是一个工作imageSrc
范围的示例(填充post.frontmatter.featuredImage.childImageSharp.fluid.src
,绕过 gatsby 的图像加载)
<span class="makeStyles-imageSrc-21" style="background-image: url("/static/8058f3f26913fea3b6a89a73344fe94a/14b42/salty_egg.jpg");"></span>
这是我的尝试输出的图像不加载留下灰色框的地方:
<span class="makeStyles-imageSrc-5 gbi--1866542702-sdWE3QALWtx7F9TPwtWxQm" style="background-position: 50% 40%; background-repeat: no-repeat; background-size: cover; position: relative; opacity: 0.99;">
<style>
.makeStyles-imageSrc-5.gbi--1866542702-sdWE3QALWtx7F9TPwtWxQm:before,
.makeStyles-imageSrc-5.gbi--1866542702-sdWE3QALWtx7F9TPwtWxQm:after {
content: '';
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: #040e18;
transition: none;
background-position: center 40%;
background-repeat: no-repeat;
background-size: cover;
background-position-x: center;
background-position-y: 40%;
}
.makeStyles-imageSrc-5.gbi--1866542702-sdWE3QALWtx7F9TPwtWxQm:before {
z-index: -100;
background-image: url('http://localhost:8000/static/8058f3f26913fea3b6a89a73344fe94a/14b42/salty_egg.jpg');
background-image: url([REMOVED BASE64 IMAGE PREVIEW FOR SO]);
opacity: 0;
}
.makeStyles-imageSrc-5.gbi--1866542702-sdWE3QALWtx7F9TPwtWxQm:after {
z-index: -101;
background-image: url('http://localhost:8000/static/8058f3f26913fea3b6a89a73344fe94a/14b42/salty_egg.jpg');
opacity: 1;
}
</style>
</span>
解决方案
我想到了!position: "absolute"
您必须通过将其传递给 the 的style
道具BackgroundImage
或将其标记!important
为imageSrc
in来强制执行useStyles
推荐阅读
- android - 使用 snapdragon MSM8998 在通话中注入上行链路音频
- math - 如何修复从“cuda_fp16.h”中找不到的数学函数
- python - 项目输出不会移动到输出文件夹(py 安装程序)
- javascript - 使用 setTimeout 混淆垃圾邮件机器人的表单
- html - 在按钮单击时将选定的值从 mat-select 发送到控制器
- android - V1 签名的 Release APK 不适用于 Android Q 测试版,但适用于 V2 签名的 APK
- git - 在合并请求中压缩新提交
- javascript - 从 DOM 中删除图像 url
- datetime - 如何在 ionic 3 中设置最小日期和时间
- javascript - VueJS - 绑定自定义道具不适用于 b-form 组件