I've been trying to find a solution for handling SVG elements used as background images via CSS:
.icon.arrow-down
{
background-image: url( 'images/spritesheet.svg#arrow-down' );
}
I'm using :target
directly in the SVG file in order to target a particular layer (or "group") within the combined 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,12.5)">
<path fill="#F00" d="M 0,25 50,25 25,0 z" />
</g>
...
</svg>
This works fine for Firefox and IE9+, but in Chrome it seems to be ignoring the #profile
part. However, going to the SVG sheet directly in the browser, with the target id, yields the correct image.
Is this a bug in the way Chrome is handling :target
in background images?
I'm trying to avoid having to separate everything into their own files, so only one resource is downloaded, but I don't know that it is possible yet.
Notice how the icons are not shown in Chrome, but are in other browsers: http://jsfiddle.net/sYL5F/1/
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…