[英]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.