简体   繁体   English

材质用户界面:嵌套组件样式替换不适用

[英]Material UI: Nested component style override not applying

I'm new to CSS in JS and I'm a bit stuck on component styles in Material UI - specifically how to override a nested element style. 我是JS中CSS的新手,但是我对Material UI中的组件样式有些犹豫,特别是如何覆盖嵌套的元素样式。 I've been following t he official docs but it's not helping. 我一直在关注他的官方文档,但没有帮助。

In the styles object I have set: 在样式对象中,我设置了:

listItemText: {
  fontSize: 0.8,
  color: '#ccc'
},
span: {
  fontSize: 0.8,
  color: '#ccc'
}

The component looks like: 该组件如下所示:

<ListItemText
  primary={text}
  classes={{
    root: classes.listItemText,
    span: classes.span
  }}
/>

As you can see in the demo linked below, the font size and colour is getting applied to the parent component, but not the nested span. 如您在下面的演示中看到的那样,字体大小和颜色将应用于父组件,而不是嵌套跨度。 How can I apply it on the span? 如何在跨度上应用它?

编辑材料演示

I figured it out. 我想到了。 Each component has it's own CSS API... 每个组件都有自己的CSS API ...

It would be better if this was documented more clearly. 如果对此进行更清晰的记录,那就更好了。

<ListItemText
  primary={obj.label}
  classes={{
    root: classes.listItemText,
    primary: classes.listItemText
  }}
/>

https://material-ui.com/api/list-item-text/ https://material-ui.com/api/list-item-text/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM