首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >矩形或圆形中的SVG图像显示为黑色

矩形或圆形中的SVG图像显示为黑色
EN

Stack Overflow用户
提问于 2012-10-06 02:06:47
回答 1查看 3.4K关注 0票数 3

我一直在stackoverflow和google上搜索,想找出我的代码不能工作的原因。我试图放置一个图像作为一个圆的填充,但它只是显示为黑色。这是我所拥有的。

代码语言:javascript
复制
<svg width="100%" height="99%">
    <defs>
        <pattern id="tile-ww" x="0" y="0" patternunits="userSpaceOnUse" width="24" height="24">    
            <img xlink:href="distributor-sprite.png" width="24" height="24" x="0" y="0">
        </pattern>
        <pattern id="tile-us" x="0" y="0" patternunits="userSpaceOnUse" width="24" height="24">
            <img xlink:href="distributor-sprite.png" width="24" height="24" x="0" y="0">
        </pattern>
    </defs>

    <g id="stage" transform="translate(80,10)">
        <g class="node" transform="translate(380,44.375)">
            <rect class="name" ry="3" rx="3" height="15" x="-32" width="32"></rect>
            <circle r="54.5" id="circle-4" fill="url(#tile-ww)"></circle>
            <text id="text-4" x="-10" dy=".35em" text-anchor="end" z="1">Jon</text>
        </g>
    </g>
</svg>

我也尝试过使用css应用该模式,但无济于事

代码语言:javascript
复制
.node circle {
    cursor: pointer;
    stroke: #282828;
    stroke-width: 1.5px;
    fill: url(#tile-ww);
}

我已经反复检查过了,图像是正确的。我尝试了相对路径和绝对路径,但没有成功。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-06 02:12:08

pattern defs中使用<image />而不是<img />。对我很管用!

<img>是一个HTML5规范元素,而<image>是SVG规范的一部分。更多信息请点击此处:http://www.w3.org/TR/SVG/struct.html#ImageElement

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12751745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档