【问题标题】:className not populated in Gatsby with Bulma布尔玛没有在 Gatsby 中填充 className
【发布时间】:2019-05-12 11:51:36
【问题描述】:

我正在尝试使用以下方法设置 div 的类名:

  render() {

    const textStyle = {
      position: "absolute",
      top: "200px",
      left: "200px"
    }

    return (
      <Layout>
        <div>
          <div>
            <div className={textStyle}> My text is Test</div>
          </div>
        </div>
      </Layout>
    )
  }
}

但是,当我检查时,我得到的只是

&lt;div class="[object Object]"&gt; My text is Test&lt;/div&gt;

我不确定为什么这不起作用。

我可以使用 Bulma 修饰符了

【问题讨论】:

    标签: reactjs gatsby bulma


    【解决方案1】:

    className 接收一个字符串,而不是一个对象

    如果你想使用你的 textStyle 对象,请使用:

    <div style={textStyle}> My text is Test</div>
    

    更多关于类名:https://reactjs.org/docs/faq-styling.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多