How to Scale an Inline SVG Element
In certain scenarios, developers may need to dynamically scale an inline SVG image to match the size of its parent container. This can be achieved without referencing an external SVG file and allows for the application of additional CSS styles to the SVG's contents.
To scale an inline SVG, use the following steps:
For example, the following code will render a triangle within a 10px by 20px bounding box, which will then be scaled to fit its parent container:
svg { border: 1px solid blue; } <svg> <polygon fill=red stroke-width=0 points="0,10 20,10 10,0" /> </svg>
By specifying the coordinates within the SVG independently of its scaled size, the image will maintain its proportions and render correctly regardless of its container's size.
The above is the detailed content of How Can I Scale an Inline SVG to Fit Its Parent Container?. For more information, please follow other related articles on the PHP Chinese website!