html - Full width image with mask -
i have responsive website imageheader (full-width). on top of image have svg mask, have have painted-like on bottom of header. problem is, image isn't scaling fit width. 100% wide , 700px high (or cover it's parent, normally: background-size: cover).
this like:
and have achieved far (the image different doesn't matter:
the code i'm using:
<div class="cover"> <svg width="100%" height="100%" baseprofile="full" version="1.2"> <defs> <mask id="svgmask2" maskunits="objectboundingbox" maskcontentunits="objectboundingbox" transform="scale(1)"> <image width="100%" height="100%" xlink:href="/images/brush-header.png" /> </mask> </defs> <image id="the-mask" mask="url(#svgmask2)" width="100%" height="100%" y="0" x="0" xlink:href="/images/header-image.png" /> </svg> </div>
where cover has css:
.cover{ height: 700px; width: 100%; }
what want: - width of image must 100%, mask must cover full image width, brush cannot image on top of: want see content of site behind header, see in second picture.
dimensions of image: 1920x1256 dimensions of brush: 1422x721
if want svg scale fit container (cover
), need tell browser how big svg's contents are. can't scale svg if has no idea how big is.
you using viewbox
attribute.
you haven't given info on how big image is. assuming, sake of example, 1024x768. change svg root tag to:
<svg width="100%" viewbox="0 0 1024 768">
you may want change preserveaspectratio
attribute positioned @ top of container:
<svg width="100%" viewbox="0 0 1024 768" preserveaspectratio="xmidymin meet">
update
here's example witha 400x200 image scaled fit page.
body { margin: 0; } .cover { height: 700px; width: 100%; }
<div class="cover"> <svg width="100%" viewbox="0 0 400 200" preserveaspectratio="xmidymin meet"> <image id="the-mask" mask="url(#svgmask2)" width="100%" height="100%" y="0" x="0" xlink:href="http://lorempixel.com/400/200/" /> </svg> </div>
Comments
Post a Comment