Responsive SVG for border

Viewed 148

I downloaded an SVG code for my web application and when I resize the window the svg does not resize.

svg code:

<div className="wave">
                <svg xmlSpace="preserve" viewBox="0 0 1995 128" y="128" x="2000" xmlnsXlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">
                    <path d="M1999.5,22.2c-346-0.6-524.6-4.7-878.8,4.4c-286.6,7.4-442.3,54-608.1,51.2C307.3,74.3,202.5,5-0.5,28.1v100.4l2000-0.5V22.2z" fill="#f4f5f7" opacity="0.2"></path>
                    <path d="M-0.3,46.1C251,15.3,440.9,84.7,499.6,98.4c54.7,12.8,122.5,12,186.7-5.3c154.2-41.6,315.5-70.9,475.2-67.5s324.6,22.4,484.3,19.7c133-2.3,302.8,1.7,352.8,3.7c0,21.3,0,80,0,80H-0.5L-0.3,46.1z" fill="#f4f5f7" opacity="0.2"></path>
                    <path d="M2000,41.2c-139.8-12.7-219.9-10.8-360.2-11.2c-285.5-0.8-487.5,18-736.2,51.1C647,115.4,546.7,116.4,199.2,53.6C140.3,43,59.5,45.6-0.5,52.3V130h2000L2000,41.2z" fill="#f4f5f7" opacity="0.4"></path>
                    <path d="M1634.6,50.1c-193.8,11.9-366.9,24.9-569,50c-110.2,13.7-221.2,21.5-332.3,19.6c-187-3.3-344.5-29.7-560.9-69.8c-122.2-22.6-172.8-4-172.8-4V130h1998V46C1997.5,46,1831,38.1,1634.6,50.1z" fill="#f4f5f7"></path>
                </svg>
</div>

.wave:

.wave {
 bottom: 0;
 display: block;
 height: 156px;
 overflow: hidden;
 position: absolute;
 right: 0;
 text-align: center;
 width: 100%;
 z-index: 1;
}

fullscreen view:

enter image description here

when I resize window:

enter image description here

How can I prevent the SVG from moving up?

1 Answers

One posible way is using your shapes as a mask. Please observe that I've added a white rectangle under your shapes and I've changed the fill to black.

Thde image will be visible under the whites parts of the mask partially visible under the shades of grey and invisible undet the black parts.

Also the image is now part of the svg element and is masked by the mask. Since the svg element has no width and height will be responsive taking all the width available.

*{margin:0;padding:0;}
<svg xmlSpace="preserve" viewBox="0 -200 1995 328" >
  <mask id="m">
  <rect y="-200" width="1995" height="328" fill="white"/>
  <path d="M1999.5,22.2c-346-0.6-524.6-4.7-878.8,4.4c-286.6,7.4-442.3,54-608.1,51.2C307.3,74.3,202.5,5-0.5,28.1v100.4l2000-0.5V22.2z"  opacity="0.2"></path>
  <path d="M-0.3,46.1C251,15.3,440.9,84.7,499.6,98.4c54.7,12.8,122.5,12,186.7-5.3c154.2-41.6,315.5-70.9,475.2-67.5s324.6,22.4,484.3,19.7c133-2.3,302.8,1.7,352.8,3.7c0,21.3,0,80,0,80H-0.5L-0.3,46.1z"  opacity="0.2"></path>
  <path d="M2000,41.2c-139.8-12.7-219.9-10.8-360.2-11.2c-285.5-0.8-487.5,18-736.2,51.1C647,115.4,546.7,116.4,199.2,53.6C140.3,43,59.5,45.6-0.5,52.3V130h2000L2000,41.2z"  opacity="0.4"></path>
  <path d="M1634.6,50.1c-193.8,11.9-366.9,24.9-569,50c-110.2,13.7-221.2,21.5-332.3,19.6c-187-3.3-344.5-29.7-560.9-69.8c-122.2-22.6-172.8-4-172.8-4V130h1998V46C1997.5,46,1831,38.1,1634.6,50.1z" ></path>
   </mask>
  <image width="1995" height="1330" y="-200" xlink:href="https://images.unsplash.com/photo-1620554602048-63902824b560?crop=entropy&cs=srgb&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYyMDczNTI3Nw&ixlib=rb-1.2.1&q=85" mask="url(#m)"/>
                </svg>

Related