javascript - 将包含图像的 Material UI GridList 制作为背景

标签 javascript css reactjs material-ui

我有一个 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>

这就是我现在的用户界面: enter image description here

我的问题在于 Hello World 文本。正如您从图像中看到的,它位于左下角。我想将该文本放在中心,并将图像的 GridList 转换为透明或灰度的背景。

我的最终目标是能够在图像的 GridList 之上添加其他 Material UI 组件。本质上,我希望图像的 GrdList 作为背景,以便我可以将其他内容放置在其顶部。

我尝试将 z-index 添加到不带外观的组件

最佳答案

GridList 和“Hello world”保留在 material-ui 提供的同一个 Box 容器中,并使用 Box 容器的 props 可以将“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>

希望对你有帮助

关于javascript - 将包含图像的 Material UI GridList 制作为背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60782774/

相关文章:

reactjs - 使用 react-testing-library 在 Jest 中模拟 React 上下文提供程序

javascript - 如何在 React 中更新我的帖子的评论

javascript - 首页设计: dynamically moving and expanding images

javascript - 将变量从 dom 元素传递到 onclick

css - 不同站点 css 到我的自定义按钮的问题

Javafx:摆脱 slider margin

javascript - jquery-selectize.js 更改了下拉列表识别问题

javascript - 无论缩放和滚动如何,都将 div 定位在特定的固定位置

html - 导航栏(国家图片无响应)

reactjs - 如何在antd中将加载器放入嵌套表中?