Home > Article > Web Front-end > How to Make Inline SVG Clip-Paths Responsive?
Responsive Clip-Path with Inline SVG
Issue:
A clip-path defined using an inline SVG is not applying the desired curvature to the parent element.
Analysis:
In the provided code, a clipPath reference is applied to an element with a background. However, the clip-path is not visible as intended.
Reason:
The clip-path referenced by url(#myClip) is defined with absolute dimensions in the inline SVG. When applied to the parent element, the clip-path dimensions are not scaled to fit the element's size, resulting in the curvature not being visible.
Solution:
To create a responsive clip-path that scales with the parent element, the clipPathUnits attribute should be set to "objectBoundingBox" on the clipPath definition. This will ensure that the clip-path dimensions are relative to the bounding box of the parent element, making it responsive.
Updated Code:
<code class="html"><header id="block-header"> <svg width="0" height="0"> <defs> <clipPath id="myClip" clipPathUnits="objectBoundingBox"> <path d="M0,0 1,0 1,0.9 C 1,0.9, 0.77,1, 0.5,1 0.23,1, 0,0.9,0,0.9z"/> </clipPath> </defs> </svg> </header></code>
By setting clipPathUnits to "objectBoundingBox", the clip-path will automatically scale to match the size of the parent element, ensuring the curvature is visible and responds to changes in element size.
The above is the detailed content of How to Make Inline SVG Clip-Paths Responsive?. For more information, please follow other related articles on the PHP Chinese website!