【问题标题】:Set style background-image on react component在反应组件上设置样式背景图像
【发布时间】:2017-09-24 05:27:51
【问题描述】:

我正在使用内联样式来更改头像背景图像。

const avatarStyle ={
  backgoundImage: "url('/images/22.jpg')"
};

const avatar() = () => <div style={avatarStyle}></div>

但是这段代码并没有在这个标签上设置任何样式。

【问题讨论】:

  • 你拼错了背景哟,否则看起来很好
  • 你的&lt;div&gt;有没有内容,或者固定的高/宽?

标签: css reactjs styles


【解决方案1】:

您在backgroundImage 上错过了r 的信件

我认为这对你有用,

const avatarStyle ={
  backgroundImage: "url('/images/22.jpg')"
};

const avatar() = () => <div style={avatarStyle}></div>

【讨论】:

    【解决方案2】:

    一切正常。你刚刚在第 2 行打错了字。 试试这个

    const avatarStyle ={
      backgroundImage: "url('/images/22.jpg')"
    };
    
    const avatar() = () => <div style={avatarStyle}></div>
    

    【讨论】:

      猜你喜欢
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 2020-07-06
      相关资源
      最近更新 更多