【发布时间】:2022-01-04 12:36:20
【问题描述】:
组件下方包含一个父网格,其中存在 2 个其他子网格。我试图实现一个硬编码的聊天 UI,我也尝试过使用 sm md 属性,但这会丢弃根据里面的文字内容。使用 sm md 属性可使网格保持恒定宽度,使用文本时可能无法完全填充,因为文本长度会不断变化。
export const Chats = () => {
return (
<>
<Grid container display={"wrap"} justifyContent={"space-between"}>
<Grid
style={{
backgroundColor: "white",
padding: "10px",
marginTop: "100px",
borderRadius:"10px"
}}
>
<Box>
<Typography>This is message 1 </Typography>
</Box>
</Grid>
<Grid
style={{
backgroundColor: "#E3F6CB",
padding: "10px",
marginTop: "100px",
borderRadius:"10px"
}}
>
<Typography>This is message 2</Typography>
</Grid>
</Grid>
</>
);
};
【问题讨论】:
-
您应该将
<Grid item ...用于子网格,例如<Grid item xs={8}>见basic setup -
我也试过了,但这会丢弃网格根据文本内容被包裹的属性
标签: reactjs material-ui grid