简体   繁体   English

SVG多边形填充图像不起作用

[英]SVG polygon fill with image not working

I had this working previously, but for some reason my Patterns do not seem to be working whatsoever. 我以前有这个工作,但是由于某种原因,我的模式似乎没有任何作用。

I have tried all ways to get this working, and it works perfectly fine with solid colour, but when I try and use a Pattern it simply goes transparent. 我已经尝试了所有方法来使它正常工作,并且在纯色下也可以正常工作,但是当我尝试使用模式时,它就变得透明了。

I even started fresh with a new SVG pattern sample, and it still didnt work either. 我什至从一个新的SVG模式样本重新开始,但它仍然没有起作用。

SVG Code SVG代码

<svg width="100" height="100">
  <defs>
    <pattern id="image" patternUnits="userSpaceOnUse" height="100" width="100">
      <image x="0" y="0" height="100" width="100" xlink:href="http://i.imgur.com/7Nlcay7.jpg"></image>
    </pattern>
  </defs>
  <circle id='top' cx="50" cy="50" r="50" fill="url(#image)"/>
</svg>

This just shows a transparent circle. 这只是显示一个透明的圆圈。 everything here is right as far as i am aware, and there is no CSS effecting 'image' 'pattern' or 'circle' elements. 据我所知,这里的一切都是正确的,并且没有影响“图像”,“图案”或“圆形”元素的CSS。

Issue in both chrome + firefox, so pretty sure its a code issue or something else on the page. 在chrome + firefox中都发出问题,因此请确定它是代码问题还是页面上的其他问题。

Trying to get it working here: http://www.slidingwardrobesexpress.co.uk/index.php?dispatch=wardrobe_tool.step1 尝试使其在这里工作: http ://www.slidingwardrobesexpress.co.uk/index.php?dispatch=wardrobe_tool.step1

The first wardrobe door should be filled with a dark red image. 第一衣柜门应充满深红色图像。

Any ideas? 有任何想法吗? I cant find any other mention of SVG patterns getting no fill when given a pattern to fill with. 给定要填充的模式时,我找不到其他任何提到SVG模式都无法填充的内容。

My actual live code is: 我实际的实时代码是:

<defs>
 <pattern id="img-lacobel_darkred"  patternUnits="userSpaceOnUse" width="50" height="50" ><image xlink:href="/{$img_path}/lacobel_aluminiumrich.jpg" x="0" y="0" /></pattern>
</defs>
<polygon class="svgDoor1 D1S1" id="D1S1P1" points="8,12 131,41 131,415 8,428" fill="url(#img-lacobel_darkred)" style="stroke:black;stroke-width:1"  />

Your actual live code is lacking width and height attributes on the <image> elements. 您实际的实时代码在<image>元素上缺少width和height属性。 In SVG 1.1 these default (rather unhelpfully) to 0. 在SVG 1.1中,这些默认值(而不是无用的)为0。

You're also using a <base> tag which is an excellent way of breaking all the references as the base is prepended to all the fragment identifiers aka those # symbols. 您还使用了<base>标记,这是打破所有引用的一种极好的方式,因为所有片段标识符(也就是那些#符号)都以base为前缀。 Removing the <base> tag makes your testcase work on your site. 删除<base>标记可使您的测试用例在您的站点上工作。 There are other solutions such as making all the URLs absolute if you really need the <base> tag to be there. 还有其他解决方案,例如,如果确实需要<base>标记,则将所有URL都设为绝对URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM