首页  >  问答  >  正文

`style`属性期望一个从样式属性到值的映射

<p>在使用React创建一个前后图像滑动器时,我遇到了这个错误。 我不知道是否需要导入它,但不幸的是它是一个外部文件。 任何提示和建议都将不胜感激</p> <pre class="brush:php;toolbar:false;"><div class="scroller scroller-top"> <svg class="scroller__thumb" xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><polygon points="0 50 37 68 37 32 0 50" style="fill:rgb(24,24,62)"/><polygon points="100 50 64 32 64 68 100 50" style="fill:rgb(24,24,62)"/></svg> </div></pre> <p>我期望看到SVG图标,但实际上抛出了一个错误,如上述描述所示</p>
P粉817354783P粉817354783403 天前420

全部回复(1)我来回复

  • P粉276064178

    P粉2760641782023-08-16 09:59:41

    您可以直接在多边形上添加fill属性,如下所示:

    <div className="scroller scroller-top">
      <svg
        className="scroller__thumb"
        xmlns="http://www.w3.org/2000/svg"
        width="100"
        height="100"
        viewBox="0 0 100 100"
      >
        <polygon points="0 50 37 68 37 32 0 50" fill="rgb(24,24,62)" />
        <polygon points="100 50 64 32 64 68 100 50" fill="rgb(24,24,62)" />
      </svg>
    </div>

    奖励:如果您使用React,则class属性应为className

    回复
    0
  • 取消回复