2

I'm using an SVG as an image mask, but I can't figure out how to make the SVG change its size when the page is resized. When I change the window size, the image inside the SVG resizes, but the SVG doesn't. Any ideas about how to solve this?

This is the SVG code:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
    viewBox="0 0 480 302" enable-background="new 0 0 480 302" xml:space="preserve">
<defs>
    <mask id="maskHome" maskUnits="objectBoundingBox">
        <path fill="#FFFFFF" d="M240,0C91,0,0,44,0,44v214c0,0,91,44,240,44s240-44,240-44V44C480,44,389,0,240,0z"/>
    </mask>
</defs>
</svg>

CSS:

.maskHome {
    mask: url("../img/maskHome.svg#maskHome");
    -webkit-mask-image: url("../img/maskHome.svg");
    height:100%;
    width: 100%;
}

HTML:

<img class="maskHome" src="img/banner2.png" width="100%" height="100%" />
user2650772
  • 21
  • 1
  • 3

1 Answers1

1

All you need to do is use cover in your mask declaration. That should work.

.maskHome {
    mask: url("../img/maskHome.svg#maskHome") center center / cover;
    -webkit-mask-image: url("../img/maskHome.svg") center center / cover;
    height:100%;
    width: 100%;
}
Milton
  • 41
  • 7