簡體   English   中英

我們如何樣式化ReactJS中material-ui創建的DOM?

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

我們如何樣式化由Material-UI創建的DOM?

我正在使用GridListTileBar,它們的title屬性生成這樣的DOM。

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

問題是,您無法使用上面的類名稱進行樣式設置,因為它將更改。 最重要的是,我無法在代碼中添加新的靜態類名稱,因為它尚不存在。

我想我可以遍歷DOM,然后使用jQuery添加一個類名,但是我認為這不是一個優雅的解決方案。 任何想法?

Title具有node類型,因此您可以傳遞任何樣式的元素,如下所示:

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

查看GridListTileBar的源GridListTileBar ,您提供給組件的所有props都會傳遞到根div

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

您應該能夠傳遞className並看到它已被應用

<GridListTileBar className='my-class' />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM