javascript - 将包含图像的 Material UI GridList 制作为背景
问题描述
我有一个 GridList ,其中包含我从外部服务检索的一堆图像。这用于创建图像库。这些图像会定期更新,因此图像库每次看起来都不同。
如何将图片库变成灰度甚至透明,然后将其用作背景,以便我可以将内容放在图片库的顶部?我希望能够将文本框、图像放在图像库的顶部。
这是我到目前为止所拥有的
<GridList cols={3}>
{
this.state.images.map(image => (
<GridListTile
rows={1}
ref={this.imageRef}
key={image.id}
style={{ padding: 0 }}
>
<img src={image.urls.regular} alt={image.alt_description} />
</GridListTile>
))
}
</GridList>
我的问题是Hello World
文本。从图像中可以看出,它位于左下角。我想将该文本放在中心,并将图像的 GridList 转换为透明或灰度缩放的背景。
我的最终目标是能够在图像的 GridList 之上添加其他 Material UI 组件。本质上,我希望图像的 GrdList 充当背景,以便我可以将其他内容放在其顶部。
我试过z-index
不看就添加到组件中
解决方案
将两者GridList
和“Hello World”保存在Box
由 提供的同一个容器中material-ui
,并通过使用Box
容器的道具,您可以将“Hello World”居中。
试试这个
<Box position="relative" >
<GridList cols={3}>
{
this.state.images.map(image => (
<GridListTile
rows={1}
ref={this.imageRef}
key={image.id}
style={{ padding: 0 }}
>
<img src={image.urls.regular} alt={image.alt_description} />
</GridListTile>
))
}
</GridList>
<Box position="absolute" top="50%" align="center" width="100%" zIndex={1}>
<Typography>Hello World</Typography>
</Box>
</Box>
我希望它有帮助
推荐阅读
- r - 使用 R 折叠具有相同名称的几何图形
- integer - 在 Coq 中以归纳方式定义整数(根据关系进行归纳定义)
- oracle - dbms_random.value 与下面的代码一起工作正常,除了需要通过分配的字段更改日期
- javascript - Okta:如何通过 SessionToken (JavaScript) 检索访问令牌
- powerbi - PowerBI 刷新来自 Dataflow 的数据
- terraform - 如何从 terraform 0.11 自动升级到 terraform 0.14?
- javascript - Shopify 主题上的无限加载按钮
- angular - 即使我放置了 ngModel,Ng-Select 也没有分配默认值
- c++ - 在visual studio中使用native cpp testframework测试c代码LNK2019
- ansible - Ansible lineinfile 追加