简体   繁体   English

如何使用 MUI 主题设置非 MUI 组件的样式?

[英]How to style non MUI Components with an MUI theme?

For example if I dynamically needed to apply MUI theme to my non-MUI components, like an <h1> .例如,如果我需要动态地将 MUI 主题应用于我的非 MUI 组件,例如<h1> If I want <h1> tags to always be the same color (from the theme color) and always use the same margin, how can I globally define that in the theme and not just generating it per-component.如果我希望<h1>标签始终具有相同的颜色(来自主题颜色)并始终使用相同的边距,我如何在主题中全局定义它,而不仅仅是为每个组件生成它。 <h1> is just an example, but my concern extends to any third party component I may use in my app. <h1>只是一个例子,但我的担忧扩展到我可能在我的应用程序中使用的任何第三方组件。

Asumming you have a ParentComponent and you wish to apply the styles to its children components:假设您有一个 ParentComponent 并且您希望将样式应用于其子组件:

const useStyles = makeStyles({
  '@global': {
    '.children-css-selector': {
      height: 100,
      width: 100,
      backgroundColor: 'blue'
    }
  }
});

export default function ParentComponent() {
  useStyles();

  return (
       your code....
  )
}

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

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