reactjs - 使用material-ui在同一行上使用2个Typography的后续行
问题描述
我在让排版进入第二行而不离开第一行时遇到了一些麻烦,例如:
我试图在这里削减不必要的代码:
<Grid item container direction="column" >
{Array.isArray(x.sense) && x.sense && x.sense.map((x, index) => (
<>
{Array.isArray(x.gloss) ?
<Grid item container direction="row">
<Typography key={index} style={{ color: "#90a4ae", fontSize: "25px", }}>
{index + 1 + '. '}
</Typography>
<Typography key={index + 1} style={{ color: "#000000", fontSize: "25px", marginLeft: "5px" }}>
{x.gloss.toString().replace(/,/g, ', ')}
</Typography>
</Grid> : null
}
</>
))}
就像他们停留在“检查元素”上一样:
我已经尝试过修改行、列、nowarps、breakwords ..但是短文本它们保持在同一行,有什么线索吗?
更新- 刚刚插入了一个“跨度”,对我来说很好用
<Typography key={index + 1} style={{ color: "#000000", fontSize: "25px", marginLeft: "5px" }}>
<span style={{ color: "#90a4ae", fontSize: "25px", }}>{index + 1 + '. '}</span>
{x.gloss.toString().replace(/,/g, ', ')} </Typography>
解决方案
只需包裹Typography
在里面<Grid item />
{
Array.isArray(x.gloss) ? (
<Grid container direction="row">
<Grid item>
<Typography key={index} style={{ color: "#90a4ae", fontSize: "25px" }}>
{index + 1 + ". "}
</Typography>
</Grid>
<Grid item>
<Typography
key={index + 1}
style={{ color: "#000000", fontSize: "25px", marginLeft: "5px" }}
>
{x.gloss.toString().replace(/,/g, ", ")}
</Typography>
</Grid>
</Grid>
) : null;
}
推荐阅读
- ansible - 如何使用ansible替换json文件中键的值
- javascript - 使用动态生成的值更新数组
- javascript - 我可以仅使用 wordpress elementor 创建带有图像和描述的团队成员滑块吗?
- excel - 自动从具有相似名称的其他工作簿中的特定工作簿中获取数据
- satellite - 我可以在谷歌引擎地图上放大吗
- java - 在 quarkus 测试容器中手动运行 flyway 反应式
- shell - 如何在 shell 脚本中使用 count 打印不同的错误
- python - Django根据另一个表中的值过滤表中的数据?
- airflow-scheduler - 气流任务正在运行但计划上升 - MWAA
- node.js - 使用加密和节点解密时捕获错误