html - 有没有办法在卡片中的 Material-UI Typography 元素中加粗一个单词而不改变渲染?
问题描述
<Typography>
我正在尝试在 React Material-UI元素(也在 Material-UI中)中加粗一个单词<Card>
。我只是使用 html 标签,它可以工作:
<Typography><b>First thing:</b> {answers[2]}</Typography>
但是当我使用它们时,它们会在加载时产生可见的文本大小调整。
我留下了嵌套<Typography>
标签,这迫使我应用一堆样式以使它们正常显示:
<Typography style={{display:'inline-flex', alignItems: 'baseline'}}><Typography variant='h6' style={{marginRight:'3px'}}>Path:</Typography> {path}</Typography>
这似乎是一个笨拙的解决方案。我错过了什么吗?像标签导致加载延迟的另一个原因<b>
,还是内置的 Material-UI 解决方案?
的完整代码<Card>
,作为参考:
<Card className={classes.card}>
<CardActionArea>
<RenderImage imageAddress={myImage} widthAndHeight={[230, 180]} style={{marginLeft: '10%'}} />
<CardContent>
<Typography style={{display:'inline-flex', alignItems: 'baseline'}}><Typography variant='h6' style={{marginRight:'3px'}}>Path:</Typography> {path}</Typography>
<Typography><b>First thing:</b> {answers[2]}</Typography>
<Typography><b>Second thing:</b> {answers[0]}</Typography>
<Typography style={{marginBottom: 0}}><b>Third thing:</b> {answers[1]}</Typography>
</CardContent>
</CardActionArea>
</Card>
解决方案
您是否尝试过使用Box
组件?
你可以做类似的事情
<Typography component='div'>Normal text <Box fontWeight='fontWeightMedium' display='inline'>medium font weight text</Box> and some more normal text</Typography>
请注意,包装器上的component='div'
prop是必需的,因为组件不能嵌套在 Typography 的 default 下。Typography
Box
p
推荐阅读
- sql - 如何使用 SQL 为每个 MANAGER_ID 的每个员工添加剩余的工资
- electron - 电子窗口商店返回错误:未知选项`--flatten'
- c# - 如何从不是从 Controller 派生的类返回 ActionResult(文件)?
- java - 如何在 FragmentPagerAdapter 中的片段之间传递数据
- javascript - 如何用 react-native 绘制梯形/梯形?
- python - 我将如何处理以下问题?
- json - 此策略包含以下错误:已禁止字段 Principal
- python - 检查多列的值是否相同(python)
- matlab - 使用旧的 MATLAB 保存格式
- angular - 角度 7 中的部分日期选择器