如何在React的svg标签中传递样式?

时间:2019-04-27 12:16:57

标签: reactjs svg

我正试图通过

const

React组件中有这个东西,但在

处出现错误
<svg class="svg-abs svg-f-btm" xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
            viewBox="0 0 1920 140" style="margin-bottom: -9px; backgroundImage:new 0 0 1920 140;" xmlSpace="preserve">
            <path class="svg-gray" d="M960,92.9C811.4,93.3,662.8,89.4,515.3,79c-138.6-9.8-277.1-26.2-409-53.3C97.8,24,0,6.5,0,0c0,0,0,140,0,140
              l960-1.2l960,1.2c0,0,0-140,0-140c0,2.7-42.1,11.3-45.8,12.2c-45.1,11-91.5,20.1-138.4,28.1c-176.2,30.1-359.9,43.8-542.9,48.9
              C1115.4,91.4,1037.7,92.7,960,92.9z"></path>
        </svg>

我该如何纠正?

2 个答案:

答案 0 :(得分:1)

您需要这样做

style={{marginBottom: “-9px”, backgroundImage: “new 0 0 1920 140”}}

答案 1 :(得分:0)

在反应中,您像这样传递它:style={{ marginBottom: -9px; backgroundImage: new 0 0 1920 140 }},对于属性,删除“-”并使用camelCase