我很好奇我何时应该使用Grid item
来利用Grid container
或justify
之类的alignItems
道具。我的印象是,这些属性只能应用于Grid item
内部的Grid container
。但是,从我的示例来看,情况似乎并非如此(请参阅:“选项二”。
例如,让我们考虑一个简单的场景:我想要一种显示三个Typography文本的方法,一个接一个,另一个之间,中间留有一些空格。
选项一: https://codesandbox.io/s/naughty-tharp-0tof1
export default function App() {
return (
<Grid
container
direction="row"
justify="space-between"
style={{ minHeight: "100px", backgroundColor: "yellow" }}
>
<Grid item>
<Typography> First text </Typography>
</Grid>
<Grid item>
<Typography> Second text </Typography>
</Grid>
<Grid item>
<Typography> Third text </Typography>
</Grid>
</Grid>
);
}
选项二: https://codesandbox.io/s/romantic-northcutt-kjbef
export default function App() {
return (
<Grid
container
direction="column"
justify="space-between"
style={{ minHeight: "100px", backgroundColor: "yellow" }}
>
<Typography> First text </Typography>
<Typography> Second text </Typography>
<Typography> Third text </Typography>
</Grid>
);
}
为什么justify
和direction
像选项二那样直接在Typography
上工作?他们不应该只在Grid item
上工作吗?