Responsive clip-path with inline SVG

后端 未结 1 902
遇见更好的自我
遇见更好的自我 2020-12-06 05:57

On an element with a background (image or solid color don\'t really matter):

I am trying

相关标签:
1条回答
  • 2020-12-06 06:42

    References to SVG clip paths are to the clip path definitions themselves and the dimensions or other attributes of the <svg> are meaningless in this context.

    What is happening in your example is that you are applying a 4000 px wide clip path to your header. Which is probably only of the order of 900 px wide. So the curvature isn't visible.

    If you want a responsive clip path, you should define it using clipPathUnits="objectBoundingBox".

    #block-header {
        background: Red;
        min-height: 100px;
        -webkit-clip-path: url(#myClip);
    	clip-path: url(#myClip);
    }
    <h1>SVG image</h1>
    <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100" viewBox="0 0 1 1" preserveAspectRatio="none"><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"/></svg>
    
    <h1><code>clip-path</code> using the same SVG</h1>
    <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>    

    Fiddle here

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