【发布时间】:2018-10-11 12:51:26
【问题描述】:
有没有办法将我的 material-ui AppBar 组件的背景属性更改为透明而无需实际更改 CSS?
我尝试了 opacity 属性,但这会降低组件内所有内容的不透明度。
下面是我在 Stripe 网站上的意思的示例。
【问题讨论】:
标签: material-ui
有没有办法将我的 material-ui AppBar 组件的背景属性更改为透明而无需实际更改 CSS?
我尝试了 opacity 属性,但这会降低组件内所有内容的不透明度。
下面是我在 Stripe 网站上的意思的示例。
【问题讨论】:
标签: material-ui
您可以将其背景颜色更改为透明并以这种方式移除盒子阴影:
<AppBar position="static" style={{ background: 'transparent', boxShadow: 'none'}}>
【讨论】:
AppBar 组件的文件顶部使用styles 变量,然后出于某种原因使用export default withStyles(styles)(AppBarComponentHere),无论我尝试什么都不起作用。
<AppBar color="transparent" elevation={0}>
【讨论】:
Any other props supplied will be provided to the root element (Paper).
内联样式可以解决问题,谢谢。但我对这种方法感到有点不舒服,因为我们通常不会使用内联样式——不管有没有 React。
我进行了更深入的研究,试图找到更适合框架的东西,这就是我想出的。
// in App.js
const GlobalCss = withStyles({
'@global': {
'.MuiAppBar-root': {
background: 'transparent',
boxShadow: 'none'
}
}
})(() => null)
然后需要将标签插入到标记中,对我来说是:
<div>
<GlobalCss />
<Router>
.
.
.
文档的相关部分是:
【讨论】: