Transparent AppBar in material-ui (React)

后端 未结 3 842
名媛妹妹
名媛妹妹 2021-02-07 15:26

Is there a way to change the background property of my material-ui AppBar component to transparent without having to actually change the CSS?

I\'ve tried th

相关标签:
3条回答
  • 2021-02-07 16:05
    <AppBar color="transparent" elevation={0}>
    
    0 讨论(0)
  • 2021-02-07 16:15

    You can change its background color to transparent and remove the box-shadow this way:

    <AppBar position="static"  style={{ background: 'transparent', boxShadow: 'none'}}>
    
    0 讨论(0)
  • 2021-02-07 16:16

    The inline styles do the trick, so thanks for that. But I felt a little uncomfortable with the approach since we wouldn't normally use inline styles--with or without React.

    I delved a little deeper to try to find something that fits more with the framework, and this is what I came up with.

    // in App.js
    const GlobalCss = withStyles({
      '@global': {
        '.MuiAppBar-root': {
          background: 'transparent',
          boxShadow: 'none'
        }
      }
    })(() => null)
    

    The tag then needs to be inserted into the markup, which for me is:

    <div>
      <GlobalCss />
      <Router>
        .
        .
        .
    

    The relevant parts of the documentation are:

    • CSS rules to override, at AppBar API > CSS;
    • setting global CSS, at Global CSS override.
    0 讨论(0)
提交回复
热议问题