【发布时间】:2020-06-06 15:00:25
【问题描述】:
我有 2 个网格,我希望其中一个为黑色背景,一个为白色背景,这两个背景都设置在 app.js 的主题中。如果我在第二个网格内传入一个白色标签道具,我想使用 theme.palette.common.black 或 theme.palette.common.white 。我尝试使用三元语句,但不知道如何实现它。
const styles = (theme) => ({
root: {
background: theme => theme.palette.common ? "black" : "white",
// background: theme.palette.common.black,
// background: theme.palette.common.white,
},
});
const HomePage = ({ classes }) => (
<>
<FullScreenBanners>
<Grid
className={classes.root}
container
spacing={0}
alignItems="center"
justify="center"
direction="column"
>
<Typography>iPhone SE</Typography>
<Typography>From £10.99/mo. or £279 with trade-in.</Typography>
<LearnMoreBuy />
<img src="./images/iphone-se.jpg" />
</Grid>
<Grid
white
className={classes.root}
container
spacing={0}
alignItems="center"
justify="center"
direction="column"
>
<Typography>iPhone 7</Typography>
<Typography>From £7/mo. or £200 with trade-in.</Typography>
<LearnMoreBuy />
<img src="./images/iphone-se.jpg" />
</Grid>
</FullScreenBanners>
</>
);
【问题讨论】:
标签: reactjs material-ui