简体   繁体   English

我们如何样式化ReactJS中material-ui创建的DOM?

[英]How do we style the DOM that is created by the material-ui in ReactJS?

How do we style the DOM that is created by the material-ui? 我们如何样式化由Material-UI创建的DOM?

I am using GridListTileBar, and their title property generate a DOM like this. 我正在使用GridListTileBar,它们的title属性生成这样的DOM。

<div class="MuiGridListTileBar-title-29" data-reactid=".0.3.0.$3/=1$3.0.1.$=11.0.0">test</div>

The thing is, you cannot style with the class name above because it will change. 问题是,您无法使用上面的类名称进行样式设置,因为它将更改。 On top of that, I cannot add a new static class name in the code because it doesn't exist yet. 最重要的是,我无法在代码中添加新的静态类名称,因为它尚不存在。

I guess I can traverse the DOM and then add a class name with jQuery, but I don't think this is the elegant solution. 我想我可以遍历DOM,然后使用jQuery添加一个类名,但是我认为这不是一个优雅的解决方案。 Any idea? 任何想法?

Title have a node type, so you can pass any styled element like this: Title具有node类型,因此您可以传递任何样式的元素,如下所示:

<GridListTileBar 
  title={
    <b
      style={{
        color:'red'
      }}
    >
      Test title
    </b>
  }
/>

Looking at the source for GridListTileBar , any props you provide to the component are passed to the root div . 查看GridListTileBar的源GridListTileBar ,您提供给组件的所有props都会传递到根div

https://github.com/mui-org/material-ui/blob/v1-beta/src/GridList/GridListTileBar.js https://github.com/mui-org/material-ui/blob/v1-beta/src/GridList/GridListTileBar.js

You should be able to pass className and see that it's applied 您应该能够传递className并看到它已被应用

<GridListTileBar className='my-class' />

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

相关问题 ReactJS:如何以编程方式打开 Material-UI 手风琴? - ReactJS: How do I open an Material-UI Accordion programmatically? 如何在 React (Material-UI) 中切换 DOM 类? - How do I toggle DOM classes in React (Material-UI)? ReactJS和Material-ui - ReactJS and material-ui 如何设置 material-ui 文本字段的样式 - How to style material-ui textfield 如何将材料表与 Material-UI 对话框相结合? (反应JS) - How to combine Material-table with Material-UI Dialog? (ReactJS) ReactJS + Material-UI:如何在每个TableRow中使用Material-UI的FlatButton和Dialog? - ReactJS + Material-UI: How to use Material-UI’s FlatButton and Dialog in each TableRow? ReactJS和Material-UI:如何仅突出Material-UI内部的内容 <Dialog> 而不是整个页面? - ReactJS & Material-UI: How to highlight just content inside Material-UI's <Dialog> and not the whole page? ReactJS with Material-UI:如何对Material-UI数组进行排序 <TableRow> 按字母顺序排列? - ReactJS with Material-UI: How to sort an array of Material-UI's <TableRow> alphabetically? ReactJS + Material-UI:如何在 ZF8FCA79E4CB15403DA20CE0F0DFB736B 之间交替 colors<table></table> 的<tablerow /> ? - ReactJS + Material-UI: How to alternate colors between Material-UI <Table/>'s <TableRow/>? ReactJS + Material-UI:如何减少 Material-UI 的列宽<TableRow/> ? - ReactJS + Material-UI: How to reduce column width of Material-UI's <TableRow/>?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM