2015-07-28 126 views
0

我一直在修补下面的代码现在一段时间了,我似乎无法做我需要做的与Chrome和Firefox的支持。我的目标是让图像填充(覆盖)SVG的整个区域。面具SVG与图像

.trap-container { 
 
    position: relative; 
 
    width: 100%; 
 
    height: 200px; 
 
} 
 
.trap-container svg { 
 
    position: absolute; 
 
} 
 
.trap-content { 
 
    display: inline-block; 
 
    position: relative; 
 
    top: 10%; 
 
    height: 80%; 
 
    width: 100%; 
 
    bottom: 10%; 
 
    color: white; 
 
}
<div class="trap-container"> 
 
    <svg width="100%" height="100%" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none"> 
 
    <polygon points="0,0 100,0 100,70 0,100"> 
 
    </polygon> 
 
    </svg> 
 
    <div class="trap-content">Legal 
 
    </div> 
 
</div>

+1

哪种图片..? –

+0

参数为了这个图像︰https://i.imgur.com/WHnTGPB.jpg?1 – Simon

+0

这将被放置在哪里?作为身体的“背景图像”?您可以修改上面的代码,以将图像与您提供的URL一起包含。 –

回答

0

可以与路径剪辑的图像,通过首先创建的路径,然后加入与被分配给路径clip-path属性的<image>元件。

.trap-container { 
 
    position: relative; 
 
    width: 100%; 
 
    height: 200px; 
 
} 
 
.trap-container svg { 
 
    position: absolute; 
 
} 
 
.trap-content { 
 
    display: inline-block; 
 
    position: relative; 
 
    top: 10%; 
 
    height: 80%; 
 
    width: 100%; 
 
    bottom: 10%; 
 
    color: black; 
 
}
<div class="trap-container"> 
 
    <svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" version="1.1" 
 
     class="svg-graphic" width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none"> 
 
    <g> 
 
     <clipPath id="banner-mask"> 
 
     <polygon points="0,0 100,0 100,70 0,100" /> 
 
     </clipPath> 
 
    </g> 
 
    <a xlink:href="http://www.stackoverflow.com"> 
 
     <image clip-path="url(#banner-mask)" height="100%" width="100%" xlink:href="https://i.imgur.com/WHnTGPB.jpg?1" /> 
 
    </a> 
 
    </svg> 
 
    <div class="trap-content">Legal</div> 
 
</div>

+0

我曾尝试过这种方法,因为您可以看到图像被拉伸。 – Simon