I want to color the background of svg text
similar to background-color
in css
I was only able to find documentation on fill
, which colors the text itself
Is it even possible?
I want to color the background of svg text
similar to background-color
in css
I was only able to find documentation on fill
, which colors the text itself
Is it even possible?
Answer by Robert Longson (@RobertLongson) with modifications:
and we have no bluring and no heavy "getBBox" :) Padding is provided by white spaces in text-element with filter. It's worked for me
The solution I have used is:
A duplicate text item is being placed, with stroke and stroke-width attributes. The stroke should match the background colour, and the stroke-width should be just big enough to create a "splodge" on which to write the actual text.
A bit of a hack and there are potential issues, but works for me!
You can add style to your text:
White, in this example. Does not work in IE :)
Instead of using a
<text>
tag, the<foreignObject>
tag can be used, which allows for XHTML content with CSS.No this is not possible, SVG elements do not have
background-...
presentation attributes.To simulate this effect you could draw a rectangle behind the text attribute with
fill="green"
or something similar (filters). Using JavaScript you could do the following:You could use a filter to generate the background.