Home  >  Q&A  >  body text

The `style` attribute expects a mapping from style attributes to values

<p>While creating a front and back image slider using React, I encountered this error. I don't know if I need to import it but unfortunately it is an external file. Any tips and suggestions would be greatly appreciated</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>I expected to see the SVG icon, but instead an error was thrown as described above</p>
P粉817354783P粉817354783403 days ago414

reply all(1)I'll reply

  • P粉276064178

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

    You can add the fill attribute directly on the polygon as follows:

    <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>

    Bonus: If you are using React, the class attribute should be className.

    reply
    0
  • Cancelreply