Filling a simple SVG in a div

前端 未结 2 1124
别那么骄傲
别那么骄傲 2021-01-25 00:53

Here is my relevant HML with SVG:

相关标签:
2条回答
  • 2021-01-25 00:56

    The fill needs to be on the path instead of the svg element.

    Also, try adding the width="24" and height="24" to the svg element.

    0 讨论(0)
  • I'm not very sure I understand your question. Maybe this is what you need:

    I've changed the viewBox to viewBox="0 3 24 18". In order to get this value I've console.log(thePath.getBBox())

    The method getBBox() returns an object with the position and the size of the bounding box of the path. I'm using this values for the new viewBox

    viewBox = bb.x bb.y bb.width bb.height

    Where bb is the bounding box.

    <div style="width:24px;height:18px;margin:0px;padding:0px;background:black;">
            <svg viewBox="0 3 24 18">
              <path id="thePath" fill="red" d="M24 12l-9-9v7h-15v4h15v7z"/>
            </svg>
         </div>

    0 讨论(0)
提交回复
热议问题