使用CSS进行SVG spritesheet定位

前端之家收集整理的这篇文章主要介绍了使用CSS进行SVG spritesheet定位前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直试图通过CSS找到处理用作背景图像的SVG元素的解决方案:
.icon.arrow-down
{
    background-image: url( 'images/spritesheet.svg#arrow-down' );
}

我正在使用:直接在SVG文件中定位,以便在组合的SVG spritesheet中定位特定层(或“组”).

<?xml version="1.0" encoding="utf-8" ?>
<svg class="icon" id="icon" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="50px" height="50px" viewBox="0 0 50 50">
    <defs>
        <style>
            rect,line { shape-rendering: crispEdges; }
            svg .icon { display: none; }
            svg .icon:target { display: inline; }
        </style>
    </defs>

    <!-- Arrows -->
    <g class="icon" id="arrow-down" transform="translate(0,12.5)">
        <path fill="#F00" d="M 0,0 50,0 25,25 z" />
    </g>
    <g class="icon" id="arrow-up" transform="translate(0,25 50,25 25,0 z" />
    </g>
    ...
</svg>

这适用于Firefox和IE9,但在Chrome中似乎忽略了#profile部分.但是,直接在浏览器中使用目标ID转到SVG表会产生正确的图像.

这是Chrome处理方式中的错误:目标是背景图像吗?

我试图避免将所有内容分成他们自己的文件,因此只下载了一个资源,但我不知道它是否可能.

请注意图标在Chrome中是如何显示的,但在其他浏览器中是如此:http://jsfiddle.net/sYL5F/1/

解决方法

这是一个已知的问题,并且特定于将其用作背景,并且由于安全问题显然不会被修复(Opera也不会显示它).如果您直接查看SVG,它可以正常工作.

@L_301_1@

SVG stacks will not be supported for CSS properties taking CSS Image
values. This includes,but is not limited to,background-image,
mask-image,border-image.

This is a resolution of the SVG and CSS WG to differ between resources
(like SVG gradients,masks,clipPath) and image values during parse
time of CSS. This is a security requirement to protect the users
privacy and safety.

See following discussions for further information:

07001

07002

你只是像老式的精灵地图一样处理你的SVG.

原文链接:https://www.f2er.com/css/217755.html

猜你在找的CSS相关文章