Change the Markup is an option
I’m the reply separately because they are two different solutions with different implications and in a way this is an extensive response that lacks its independence.
By amending the Markup that you are currently using, you can handle the SVG support issue without having to increment your stylesheet or script file with lines of code that will only serve a small percentage of visitors.
The solution presented is based on the fact that browsers make the tag image
a pseudonym for the tag img
, as explained in Having fun with <image>
(English) by Jake Archibald where we can read:
- Firefox aliases 'image' to 'img' at parse-time
- Chrome & Safari alias 'image' to 'img' at element-Creation time
- IE aliases 'image' to 'img' throughout the Runtime
That (+/-) translated:
- Firefox converts
image
for img
when parsing
- Chrome & Safari convert
image
for img
when creating the element
- IE converts
image
for img
in the course of processing
Therefore, the idea is to make use of the tag svg
with a image
inside where we indicate the two files to be used, the SVG if supported and the fallback image in case it is needed.
<svg width="400" height="400">
<image xlink:href="http://www.quatrocubos.com.br/img/qq.svg" src="http://www.quatrocubos.com.br/img/qq.png" width="400" height="400"/>
</svg>
The question here is whether or not you can host the Markup which is obviously necessary to implement this solution.
Assuming yes, this is how things would turn out for the same effect:
Example in Jsfiddle
HTML
<div class="bg">
<div class="logo">
<svg width="500" height="500">
<image xlink:href="http://www.quatrocubos.com.br/img/qq.svg" src="http://www.quatrocubos.com.br/img/qq.png" width="500" height="500"/>
</svg>
</div>
</div>
CSS
.logo {
display:block;
width:500px;
height:500px;
margin:40px;
}
.bg{
background-color:#333;
}
Upshot
The result after adding Markup to SVG and after removing CSS now unnecessary, is as seen below or in Jsfiddle:
This gives us the same visual environment that was initially achieved primarily using CSS definitions.
Note:
As we can see in SVG Fallbacks by Chris Coyier (English) which also talks about the links already present in this answer and the technique suggested here:
In Internet Explorer we can see that both images are requested from the server. However, only one can be downloaded, the unnecessary image comes with 0KB, which tells us that the browser at some point cancels the request because it understands that after all it does not need the image.
Can you give an example how you do it? No jsFiddle maybe?
– Fernando Leal
@Fernando, an example of how I do with SVG is on the link: http://jsfiddle.net/cZ33j/
– 2madera