How to make a <svg> element expand or contract to its parent container?

后端 未结 5 1865
日久生厌
日久生厌 2020-11-28 02:26

The goal is to have the element expand to the size of its parent container, in this case a

, no matter how big or small that
5条回答
  •  误落风尘
    2020-11-28 03:05

    The viewBox isn't the height of the container, it's the size of your drawing. Define your viewBox to be 100 units in width, then define your rect to be 10 units. After that, however large you scale the SVG, the rect will be 10% the width of the image.

提交回复
热议问题