Is it possible to have background for text in svg or css? it means , every character have background? here is the example:
I have made this in photoshop and made a mask, i just wonder i it is possible in svg or css?
Here is an example using a pattern. It uses <tspan>
elements with patterned fill to show you how this may be done on a per-character basis, if desired:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:x="http://www.w3.org/1999/xlink">
<style>
svg { background:#ddd }
text {
font-family:Verdana; font-size:160pt; font-weight:bold;
stroke:#000;
}
</style>
<defs>
<pattern id="p1" patternUnits="userSpaceOnUse" width="32" height="32">
<image x:href="alphaball.png" width="32" height="32" />
</pattern>
<pattern id="p2" patternUnits="userSpaceOnUse" width="10" height="10">
<image x:href="grid.gif" width="10" height="10" />
</pattern>
</defs>
<text x="20" y="170" fill="url(#p1)">
Hello
<tspan x="20" y="350"
fill="url(#p2)">Wo<tspan fill="url(#p1)">r</tspan>ld</tspan>
</text>
</svg>
You can use a mask or a clipPath to do this too, in addition to the way with patterns as in the answers robertc suggested.
Here's an example from the svg testsuite using clipPath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With