Set background in React.js using style

前端 未结 4 1622
情歌与酒
情歌与酒 2021-02-13 18:19

I want to add a background image in React.js by using a style definition, which works:

let imgUrl = \'images/berlin.jpg\'    
let styles = {
        root: {
             


        
4条回答
  •  北海茫月
    2021-02-13 18:51

    Clarifing another answer

    let imgUrl = 'images/berlin.jpg'
    let styles = {
        root: {
           backgroundImage: `url(${ imgUrl })`
           backgroundRepeat  : 'no-repeat',
           backgroundPosition: 'center',
      }
    }

提交回复
热议问题