On 24/4/13 at 15:12,
hero...@gmail.com (Tom Herold) wrote:
>I have an SVG containing multiple foreignObjects with HTML
>inside. I would like to style these foreignObjects elements
>like you would any other SVG element by adding a border
>("stroke") and a background color ("fill"), maybe round the
>corners. According to the W3C (
><
http://www.w3.org/TR/SVG/extend.html#ForeignObjectElement>)
>the foreignObject element supports "style". However I am unable
>to style it in any way.
Provided you have a <body> or <html> element in your foreign
object, you can apply the styles you want. In the code below
you can substitute 'html' for 'body' thoughout with similar results.
<svg width="500" height="500" version="1.1"
xmlns = '
http://www.w3.org/2000/svg'>
<style>
.loud {
color:red;
font-family:verdana, sans-serif;
font-size:16pt;
}
body{
padding: 0.5em;
background-color:beige;
border:solid;
}
</style>
<rect x="10" y="10" width="100" height="100"
stroke="navy" fill="darkorchid" />
<g class="loud">
<foreignObject y="110"
width="14em" height="5em">
<body xmlns="
http://www.w3.org/1999/xhtml">
<p>Here are two squares</p>
</body>
</foreignObject>
</g>
<rect x="10" y="222" width="100" height="100"
stroke="saddlebrown" fill="gold" />
</svg>