Quote:
Originally Posted by johnsmith153
|
I don't think this is generally possible.
I was able to get it to work in Internet Explorer 10, but only for SVG images displayed via the
object element (via data URI and an external file). That's a bad thing though because Internet Explorer's behavior with the
object element ends up being inconsistent with the other delivery methods (inline SVG and the
img element); all of the other browsers display the SVG image consistently regardless of the delivery method.
Note that in order to test, I had to set the
width and
height attributes (whose values I based on the view box) since browsers do not handle the
viewBox attribute consistently. In particular, Google Chrome 23 renders the image much taller than the other browsers tested.
The code I used:
page.xhtml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
<head>
<title>Demo</title>
<style>
/* Layout */
* { margin: 0; }
svg, object, img { display: block; }
object { height: 100%; }
.box { width: 30%; margin: 2em; border-width: 1px; border-style: solid; }
/* Color Scheme */
.box { border-color: red; }
</style>
</head>
<body>
<div class="box">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400px" height="200px" viewBox="0 0, 400 200">
<style>
polygon { fill: lime; stroke-width: 1; stroke: purple; }
</style>
<polygon points="220 10, 300 210, 170 250, 123 234"/>
</svg>
</div>
<div class="box">
<object type="image/svg+xml" data="data:image/svg+xml;charset=UTF-8,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20width%3D%22400px%22%20height%3D%22200px%22%20viewBox%3D%220%200%2C%20400%20200%22%3E%0A%09%3Cstyle%3E%0A%09%09polygon%20%7B%20fill%3A%20lime%3B%20stroke-width%3A%201%3B%20stroke%3A%20purple%3B%20%7D%0A%09%3C%2Fstyle%3E%0A%09%3Cpolygon%20points%3D%22220%2010%2C%20300%20210%2C%20170%20250%2C%20123%20234%22%2F%3E%0A%3C%2Fsvg%3E">
<p>This image depicts a green, pyramidal triangle.</p>
</object>
</div>
<div class="box">
<object type="image/svg+xml" data="image.svg">
<p>This image depicts a green, pyramidal triangle.</p>
</object>
</div>
<div class="box">
<img alt="This image depicts a green, pyramidal triangle." src="image.svg"/>
</div>
</body>
</html>
image.svg
Code:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400px" height="200px" viewBox="0 0, 400 200">
<style>
polygon { fill: lime; stroke-width: 1; stroke: purple; }
</style>
<polygon points="220 10, 300 210, 170 250, 123 234"/>
</svg>