SVG center text in circle - css
I'm trying to center text in a circle with svg.
the size of the text will be dynamic.
Thank's
Avi
plunker
My code:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" viewBox="0 0 500 500">
<g id="UrTavla">
<circle style="fill:url(#toning);stroke:#010101;stroke-width:1.6871;stroke-miterlimit:10;" cx="250" cy="250" r="245">
</circle>
<text x="50%" y="50%" stroke="#51c5cf" stroke-width="2px" dy=".3em"> Look, I’m centered!Look, I’m centered! </text>
</g>
</svg>
Add text-anchor="middle" to the text element.
Plunker
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd"
viewBox="0 0 500 500">
<g id="UrTavla">
<circle style="fill:url(#toning);stroke:#010101;stroke-width:1.6871;stroke-miterlimit:10;" cx="250" cy="250" r="245">
</circle>
<text x="50%" y="50%" text-anchor="middle" stroke="#51c5cf" stroke-width="2px" dy=".3em">Look, I’m centered!Look, I’m centered!</text>
</g>
</svg>
The solution proposed and accepted is INVALID when you want to draw a circle that is not centered on container !
Using x="50%" y="50%" on text tag works only when SVG element contains a circle that is centered on viewPort.
If you want to draw 3 circles, you must also change (x,y) text coordinates so that they are equal to (cx,cy) circle coordinates has done in following example
As proposed by random, I have added alignment-baseline="middle" for first circle in code snippet only so you can see that for Label text is now perfectly aligned (vertically).
<svg height="350" width="350">
<circle cx="110" cy="110" r="100"
stroke="red"
stroke-width="3"
fill="none"
/>
<text x="110" y="110"
text-anchor="middle"
stroke="red"
stroke-width="1px"
alignment-baseline="middle"
> Label
</text>
<circle cx="240" cy="110" r="100"
stroke="blue"
stroke-width="3"
fill="none"
/>
<text x="240" y="110"
text-anchor="middle"
stroke="blue"
stroke-width="1px"
> Ticket
</text>
<circle cx="170" cy="240" r="100"
stroke="green"
stroke-width="3"
fill="none"
/>
<text x="170" y="240"
text-anchor="middle"
stroke="green"
stroke-width="1px"
> Vecto
</text>
</svg>
Just for the fun, I have put code with 3 circles to select each parts. Just click on it !
function setReadableCode()
{
var circLabel = document.getElementById('circLabel');
var circTicket = document.getElementById('circTicket');
var circVecto = document.getElementById('circVecto');
var interLabelTicket = document.getElementById('interLabelTicket');
var interTicketVecto = document.getElementById('interTicketVecto');
var interVectoLabel = document.getElementById('interVectoLabel');
var interLabelTicketVecto = document.getElementById('interLabelTicketVecto');
}
function clickCircle(sCircle, sInter2a, sInter2b, sInter3)
{
var circ = document.getElementById(sCircle);
var inter2a = document.getElementById(sInter2a);
var inter2b = document.getElementById(sInter2b);
var inter3 = document.getElementById(sInter3);
var sColor = '';
if (circ.style.fill == '' || circ.style.fill == 'white')
{
sColor = 'yellow';
}
else
{
sColor = 'white';
}
circ.style.fill = sColor;
inter2a.style.fill = sColor;
inter2b.style.fill = sColor;
inter3.style.fill = sColor;
setReadableCode();
}
function clickCircLabel() {
clickCircle('circLabel', 'interLabelTicket', 'interVectoLabel', 'interLabelTicketVecto');
}
function clickCircTicket() {
clickCircle('circTicket', 'interLabelTicket', 'interTicketVecto', 'interLabelTicketVecto');
}
function clickCircVecto() {
clickCircle('circVecto', 'interVectoLabel', 'interTicketVecto', 'interLabelTicketVecto');
}
function clickIntersection2(sInter2, sInter3) {
var inter2 = document.getElementById(sInter2);
var inter3 = document.getElementById(sInter3);
var sColor = '';
if (inter2.style.fill == '' || inter2.style.fill == 'white') {
sColor = 'yellow';
}
else {
sColor = 'white';
}
inter2.style.fill = sColor;
inter3.style.fill = sColor;
setReadableCode();
}
function clickInterLabelTicket() {
clickIntersection2('interLabelTicket', 'interLabelTicketVecto');
}
function clickInterTicketVecto() {
clickIntersection2('interTicketVecto', 'interLabelTicketVecto');
}
function clickInterVectoLabel() {
clickIntersection2('interVectoLabel', 'interLabelTicketVecto');
}
function clickInterLabelTicketVecto() {
var inter = document.getElementById('interLabelTicketVecto');
var sColor = '';
if (inter.style.fill == '' || inter.style.fill == 'white') {
sColor = 'yellow';
}
else {
sColor = 'white';
}
inter.style.fill = sColor;
setReadableCode();
}
text
{
font-family:Arial;
}
<svg height="350" width="350">
<circle id="circLabel" cx="110" cy="110" r="100" stroke="red" stroke-width="0" fill="white" onclick="clickCircLabel();"/>
<text x="60" y="110" text-anchor="middle" stroke="red" stroke-width="1px" onclick="clickCircLabel();">Label</text>
<circle id="circTicket" cx="210" cy="110" r="100" stroke="blue" stroke-width="0" fill="yellow" onclick="clickCircTicket();"/>
<text x="260" y="110" text-anchor="middle" stroke="blue" stroke-width="1px" onclick="clickCircTicket();">Ticket</text>
<circle id="circVecto" cx="160" cy="196.602541" r="100" stroke="green" stroke-width="0" fill="white" onclick="clickCircVecto();" />
<text x="160" y="240" text-anchor="middle" stroke="green" stroke-width="1px" onclick="clickCircVecto();">Vecto</text>
<path id="interLabelTicket"
d="M 160 23.397460 a100,100 0 0,0 0,173.205081 a100,100 0 0,0 0,-173.205081 z"
fill="white"
stroke-width="3"
onclick="clickInterLabelTicket();"
/>
<path id="interVectoLabel"
d="M 60 196.602541 a100,100 0 0,0 150,-86.602540 a100,100 0 0,0 -150,86.602540 z"
fill="white"
stroke-width="3"
onclick="clickInterVectoLabel();"
/>
<path id="interTicketVecto"
d="M 260 196.602541 a100,100 0 0,0 -150,-86.602540 a100,100 0 0,0 150,86.602540 z"
fill="white"
stroke-width="3"
onclick="clickInterTicketVecto();"
/>
<path id="interLabelTicketVecto"
d="M 110 110 a100,100 0 0,1 100,0 a100,100 0 0,1 -50,86.602540 a100,100 0 0,1 -50,-86.602540 z"
fill="none"
stroke-width="3"
onclick="clickInterLabelTicketVecto();"
/>
<circle cx="110" cy="110" r="100" stroke="red" stroke-width="3" fill="none" />
<circle cx="210" cy="110" r="100" stroke="blue" stroke-width="3" fill="none" />
<circle cx="160" cy="196.602541" r="100" stroke="green" stroke-width="3" fill="none"/>
</svg>
Maybe, could be useful also alignment-baseline="middle", with text-anchor="middle":
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" viewBox="0 0 500 500">
<g id="UrTavla">
<circle style="fill:url(#toning);stroke:#010101;stroke-width:1.6871;stroke-miterlimit:10;" cx="250" cy="250" r="245" /> <!--self-closing tag-->
<text x="50%" y="50%" stroke="#51c5cf" stroke-width="2px" dy=".3em" text-anchor="middle" alignment-baseline="middle"> Look, I’m centered!Look, I’m centered! </text>
</g>
</svg>
Here a good resource:
http://apike.ca/prog_svg_text_style.html
Cheers
A simpler solution that works with non-centered circles is to put circles and texts inside translated groups.
That way you don't need to repeat the coordinates on the text.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Centered texts</title>
</head>
<body ng-controller="MainCtrl">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500">
<g transform="translate(300, 300)" >
<circle fill="none" stroke="black" stroke-width="1px" r="120"/>
<text stroke="blue" stroke-width="1px" text-anchor="middle" alignment-baseline="central">Look, I’m centered!</text>
</g>
<g transform="translate(150, 150)" >
<circle fill="none" stroke="black" stroke-width="1px" r="120"/>
<text stroke="blue" stroke-width="1px" text-anchor="middle" alignment-baseline="central">Look, I’m also centered!</text>
</g>
</svg>
</body>
</html>
The behaviors are not consistent across browsers using alignment-baseline="central". Notably, Chrome will position correctly but Firefox will not. If you use dominant-baseline="central" it will appear correctly in both.
<svg viewBox="0 0 500 500" role="img" xmlns="http://www.w3.org/2000/svg">
<g id="myid">
<circle stroke="darkgray" stroke-width="1px" fill="lightgray" cx="250" cy="250" r="245"/>
<text style="font: bold 10rem sans-serif;" text-anchor="middle" dominant-baseline="central" x="50%" y="50%">Centered</text>
</g>
</svg>
it is super easy to make text center in SVG circle.
<svg height="300" width="300">
<circle cx="120" cy="120" r="30%" fill="#117da9" />
<text x="50" y="120" fill="white">Center Text in SVG Circle</text>
</svg>
All you need to do is change <text> tag x and y values until the given text align in the center of the circle.
For example, here x and y values are x="50" y="120"
Related
I have an SVG with a linear gradient applied to the fill and it isn't applying the second stop color and I can't figure out why
I have an SVG with a linear gradient defined that I am applying the colors to using CSS. In practice though, it's only displaying the first color. In the CSS, I can see that the second stop-color is getting the orange rule, but it's not showing up in the SVG and I can't figure out why. In the code below, the image shows up as solid blue. linearGradient:nth-child(2n+1) stop:first-child { stop-color: blue; } linearGradient:nth-child(2n+1) stop:nth-child(2) { stop-color: orange; } <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="100%" height="100%" viewBox="0 0 265 255" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"> <defs> <linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(-1.68,-154.08,154.08,-1.68,61.68,180)"> <stop offset="0" style="stop-opacity:1"/> <stop offset="1" style="stop-opacity:1"/> </linearGradient> </defs> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M2918.29,629.251L2934.79,629.251L2934.79,631.958C2934.79,635.75 2937.87,638.837 2941.67,638.837C2945.36,638.837 2948.47,635.685 2948.47,631.958L2948.47,629.251L2990.32,629.251L2990.32,631.958C2990.32,635.75 2993.41,638.837 2997.2,638.837C3000.95,638.837 3004,635.75 3004,631.958L3004,629.251L3045.92,629.251L3045.92,631.958C3045.92,635.75 3048.97,638.837 3052.73,638.837C3056.52,638.837 3059.6,635.75 3059.6,631.958L3059.6,629.251L3101.45,629.251L3101.45,631.958C3101.45,635.75 3104.54,638.837 3108.33,638.837C3112.08,638.837 3115.14,635.75 3115.14,631.958L3115.14,629.251L3131.63,629.251C3134.25,629.251 3136.37,631.377 3136.37,633.983L3136.37,654.855L2913.55,654.855L2913.55,633.983C2913.55,631.377 2915.67,629.251 2918.29,629.251ZM2940.3,620.944C2940.3,620.248 2940.93,619.659 2941.67,619.659C2942.35,619.659 2942.96,620.262 2942.96,620.944L2942.96,631.958C2942.95,633.43 2940.3,633.358 2940.3,631.958L2940.3,620.944ZM2995.83,620.944C2995.83,620.248 2996.46,619.659 2997.2,619.659C2997.92,619.659 2998.49,620.226 2998.49,620.944L2998.49,631.958C2998.49,633.48 2995.83,633.395 2995.83,631.958L2995.83,620.944ZM3051.43,620.944C3051.43,620.226 3052,619.659 3052.73,619.659C3053.47,619.659 3054.09,620.248 3054.09,620.944L3054.09,631.958C3054.09,633.395 3051.43,633.48 3051.43,631.958L3051.43,620.944ZM3106.96,620.944C3106.96,620.248 3107.59,619.659 3108.33,619.659C3109.05,619.659 3109.62,620.226 3109.62,620.944L3109.62,631.958C3109.62,633.48 3106.96,633.395 3106.96,631.958L3106.96,620.944ZM2908.03,633.983L2908.03,804.918C2908.03,810.569 2912.64,815.171 2918.29,815.171L3079.48,815.171C3081,815.171 3082.24,813.937 3082.24,812.414C3082.24,810.892 3081,809.657 3079.48,809.657L2918.29,809.657C2915.67,809.657 2913.55,807.532 2913.55,804.918L2913.55,660.37L3136.37,660.37L3136.37,756.432C3136.37,757.954 3137.61,759.188 3139.13,759.188C3140.65,759.188 3141.89,757.954 3141.89,756.432L3141.89,657.684C3141.89,657.659 3141.9,657.638 3141.9,657.613C3141.9,657.587 3141.89,657.567 3141.89,657.542L3141.89,633.983C3141.89,628.333 3137.29,623.737 3131.63,623.737L3115.14,623.737L3115.14,620.944C3115.14,617.196 3112.08,614.145 3108.33,614.145C3104.54,614.145 3101.45,617.196 3101.45,620.944L3101.45,623.737L3059.6,623.737L3059.6,620.944C3059.6,617.196 3056.52,614.145 3052.73,614.145C3048.97,614.145 3045.92,617.196 3045.92,620.944L3045.92,623.737L3004,623.737L3004,620.944C3004,617.196 3000.95,614.145 2997.2,614.145C2993.41,614.145 2990.32,617.196 2990.32,620.944L2990.32,623.737L2948.47,623.737L2948.47,620.944C2948.47,617.196 2945.42,614.145 2941.67,614.145C2937.87,614.145 2934.79,617.196 2934.79,620.944L2934.79,623.737L2918.29,623.737C2912.64,623.737 2908.03,628.333 2908.03,633.983Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3109.62,747.995L3056.86,747.995L3056.86,720.237L3109.62,720.237L3109.62,747.995ZM3051.35,781.267L2998.58,781.267L2998.58,753.509L3051.35,753.509L3051.35,781.267ZM2940.3,753.509L2993.07,753.509L2993.07,781.267L2940.3,781.267L2940.3,753.509ZM2940.3,720.237L2993.07,720.237L2993.07,747.995L2940.3,747.995L2940.3,720.237ZM2998.58,686.965L3051.35,686.965L3051.35,714.723L2998.58,714.723L2998.58,686.965ZM2998.58,747.995L2998.58,720.237L3051.35,720.237L3051.35,747.995L2998.58,747.995ZM3109.62,714.723L3056.86,714.723L3056.86,686.965L3109.62,686.965L3109.62,714.723ZM3115.14,750.752L3115.14,684.208C3115.14,682.686 3113.9,681.45 3112.38,681.45L2995.82,681.45C2994.3,681.45 2993.07,682.686 2993.07,684.208L2993.07,714.723L2937.54,714.723C2936.02,714.723 2934.79,715.958 2934.79,717.48L2934.79,784.024C2934.79,785.546 2936.02,786.782 2937.54,786.782L3054.11,786.782C3055.63,786.782 3056.86,785.546 3056.86,784.024L3056.86,753.509L3112.38,753.509C3113.9,753.509 3115.14,752.274 3115.14,750.752Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3085.29,798.679C3085.53,798.75 3085.78,798.779 3086.02,798.779C3087.23,798.779 3088.34,797.982 3088.68,796.755L3089.51,793.753C3091.82,785.389 3095.38,778.654 3100.08,773.75C3101.13,772.644 3101.1,770.899 3100,769.851C3098.89,768.789 3097.14,768.839 3096.1,769.93C3090.76,775.509 3086.75,783.026 3084.2,792.274L3083.36,795.29C3082.95,796.755 3083.82,798.277 3085.29,798.679Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3159.47,796.755C3159.81,797.982 3160.92,798.779 3162.13,798.779C3162.37,798.779 3162.62,798.75 3162.86,798.679C3164.33,798.277 3165.19,796.755 3164.79,795.29L3163.95,792.289C3161.4,783.026 3157.39,775.509 3152.05,769.93C3150.99,768.839 3149.25,768.789 3148.15,769.851C3147.05,770.899 3147.01,772.644 3148.07,773.75C3152.77,778.654 3156.33,785.389 3158.64,793.768L3159.47,796.755Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3107.96,856.809L3141.33,856.809C3139.18,860.384 3133.01,863.493 3124.65,863.493C3116.28,863.493 3110.11,860.384 3107.96,856.809ZM3082.21,848.53C3082.3,847.855 3084.23,846.024 3085.5,844.818C3088.94,841.558 3093.63,837.106 3095.76,829.783C3098.23,821.224 3101.71,808.717 3104.68,797.954C3109.7,779.853 3119.25,779.989 3124.91,779.875C3129.95,779.91 3139.6,779.853 3144.61,797.954C3147.58,808.717 3151.06,821.217 3153.53,829.783C3155.66,837.106 3160.36,841.558 3163.79,844.818C3165.07,846.031 3167,847.862 3167.09,848.487C3167.09,848.487 3166.95,848.946 3166.06,849.65C3163.53,850.611 3148.55,851.154 3132.01,851.294L3115.28,851.294C3099.62,851.17 3085.84,850.686 3083.56,849.844C3082.39,848.989 3082.22,848.53 3082.21,848.53ZM3147.31,856.452C3158.82,856.057 3167.58,855.332 3169.01,854.281C3171.3,852.594 3172.47,850.82 3172.59,848.853C3172.78,845.744 3170.37,843.461 3167.59,840.812C3164.45,837.839 3160.54,834.134 3158.83,828.246C3156.36,819.709 3152.9,807.223 3149.92,796.489C3144.66,777.496 3134.12,774.771 3127.41,774.413L3127.41,766.563C3127.41,765.041 3126.17,763.806 3124.65,763.806C3123.13,763.806 3121.89,765.041 3121.89,766.563L3121.89,774.38C3115.39,774.642 3104.73,777.113 3099.37,796.489C3096.4,807.223 3092.93,819.702 3090.46,828.246C3088.76,834.134 3084.85,837.839 3081.71,840.818C3078.92,843.461 3076.51,845.744 3076.7,848.853C3076.82,850.813 3077.99,852.594 3080.28,854.281C3081.71,855.332 3090.47,856.057 3101.98,856.452C3103.71,863.65 3113,869.007 3124.65,869.007C3136.29,869.007 3145.58,863.65 3147.31,856.452Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> </svg>
linearGradient stop:first-child { stop-color: blue; } linearGradient stop:last-child { stop-color: orange; }
Removing the gradientUnit and gradientTransform properties gave me the result I wanted! linearGradient:nth-child(2n+1) stop:first-child { stop-color: blue; } linearGradient:nth-child(2n+1) stop:nth-child(2) { stop-color: orange; } <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="100%" height="100%" viewBox="0 0 265 255" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"> <defs> <linearGradient id="_Linear1" x1="0" y1="1" x2="0" y2="0" > <stop offset="0" style="stop-opacity:1"/> <stop offset="1" style="stop-opacity:1"/> </linearGradient> </defs> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M2918.29,629.251L2934.79,629.251L2934.79,631.958C2934.79,635.75 2937.87,638.837 2941.67,638.837C2945.36,638.837 2948.47,635.685 2948.47,631.958L2948.47,629.251L2990.32,629.251L2990.32,631.958C2990.32,635.75 2993.41,638.837 2997.2,638.837C3000.95,638.837 3004,635.75 3004,631.958L3004,629.251L3045.92,629.251L3045.92,631.958C3045.92,635.75 3048.97,638.837 3052.73,638.837C3056.52,638.837 3059.6,635.75 3059.6,631.958L3059.6,629.251L3101.45,629.251L3101.45,631.958C3101.45,635.75 3104.54,638.837 3108.33,638.837C3112.08,638.837 3115.14,635.75 3115.14,631.958L3115.14,629.251L3131.63,629.251C3134.25,629.251 3136.37,631.377 3136.37,633.983L3136.37,654.855L2913.55,654.855L2913.55,633.983C2913.55,631.377 2915.67,629.251 2918.29,629.251ZM2940.3,620.944C2940.3,620.248 2940.93,619.659 2941.67,619.659C2942.35,619.659 2942.96,620.262 2942.96,620.944L2942.96,631.958C2942.95,633.43 2940.3,633.358 2940.3,631.958L2940.3,620.944ZM2995.83,620.944C2995.83,620.248 2996.46,619.659 2997.2,619.659C2997.92,619.659 2998.49,620.226 2998.49,620.944L2998.49,631.958C2998.49,633.48 2995.83,633.395 2995.83,631.958L2995.83,620.944ZM3051.43,620.944C3051.43,620.226 3052,619.659 3052.73,619.659C3053.47,619.659 3054.09,620.248 3054.09,620.944L3054.09,631.958C3054.09,633.395 3051.43,633.48 3051.43,631.958L3051.43,620.944ZM3106.96,620.944C3106.96,620.248 3107.59,619.659 3108.33,619.659C3109.05,619.659 3109.62,620.226 3109.62,620.944L3109.62,631.958C3109.62,633.48 3106.96,633.395 3106.96,631.958L3106.96,620.944ZM2908.03,633.983L2908.03,804.918C2908.03,810.569 2912.64,815.171 2918.29,815.171L3079.48,815.171C3081,815.171 3082.24,813.937 3082.24,812.414C3082.24,810.892 3081,809.657 3079.48,809.657L2918.29,809.657C2915.67,809.657 2913.55,807.532 2913.55,804.918L2913.55,660.37L3136.37,660.37L3136.37,756.432C3136.37,757.954 3137.61,759.188 3139.13,759.188C3140.65,759.188 3141.89,757.954 3141.89,756.432L3141.89,657.684C3141.89,657.659 3141.9,657.638 3141.9,657.613C3141.9,657.587 3141.89,657.567 3141.89,657.542L3141.89,633.983C3141.89,628.333 3137.29,623.737 3131.63,623.737L3115.14,623.737L3115.14,620.944C3115.14,617.196 3112.08,614.145 3108.33,614.145C3104.54,614.145 3101.45,617.196 3101.45,620.944L3101.45,623.737L3059.6,623.737L3059.6,620.944C3059.6,617.196 3056.52,614.145 3052.73,614.145C3048.97,614.145 3045.92,617.196 3045.92,620.944L3045.92,623.737L3004,623.737L3004,620.944C3004,617.196 3000.95,614.145 2997.2,614.145C2993.41,614.145 2990.32,617.196 2990.32,620.944L2990.32,623.737L2948.47,623.737L2948.47,620.944C2948.47,617.196 2945.42,614.145 2941.67,614.145C2937.87,614.145 2934.79,617.196 2934.79,620.944L2934.79,623.737L2918.29,623.737C2912.64,623.737 2908.03,628.333 2908.03,633.983Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3109.62,747.995L3056.86,747.995L3056.86,720.237L3109.62,720.237L3109.62,747.995ZM3051.35,781.267L2998.58,781.267L2998.58,753.509L3051.35,753.509L3051.35,781.267ZM2940.3,753.509L2993.07,753.509L2993.07,781.267L2940.3,781.267L2940.3,753.509ZM2940.3,720.237L2993.07,720.237L2993.07,747.995L2940.3,747.995L2940.3,720.237ZM2998.58,686.965L3051.35,686.965L3051.35,714.723L2998.58,714.723L2998.58,686.965ZM2998.58,747.995L2998.58,720.237L3051.35,720.237L3051.35,747.995L2998.58,747.995ZM3109.62,714.723L3056.86,714.723L3056.86,686.965L3109.62,686.965L3109.62,714.723ZM3115.14,750.752L3115.14,684.208C3115.14,682.686 3113.9,681.45 3112.38,681.45L2995.82,681.45C2994.3,681.45 2993.07,682.686 2993.07,684.208L2993.07,714.723L2937.54,714.723C2936.02,714.723 2934.79,715.958 2934.79,717.48L2934.79,784.024C2934.79,785.546 2936.02,786.782 2937.54,786.782L3054.11,786.782C3055.63,786.782 3056.86,785.546 3056.86,784.024L3056.86,753.509L3112.38,753.509C3113.9,753.509 3115.14,752.274 3115.14,750.752Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3085.29,798.679C3085.53,798.75 3085.78,798.779 3086.02,798.779C3087.23,798.779 3088.34,797.982 3088.68,796.755L3089.51,793.753C3091.82,785.389 3095.38,778.654 3100.08,773.75C3101.13,772.644 3101.1,770.899 3100,769.851C3098.89,768.789 3097.14,768.839 3096.1,769.93C3090.76,775.509 3086.75,783.026 3084.2,792.274L3083.36,795.29C3082.95,796.755 3083.82,798.277 3085.29,798.679Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3159.47,796.755C3159.81,797.982 3160.92,798.779 3162.13,798.779C3162.37,798.779 3162.62,798.75 3162.86,798.679C3164.33,798.277 3165.19,796.755 3164.79,795.29L3163.95,792.289C3161.4,783.026 3157.39,775.509 3152.05,769.93C3150.99,768.839 3149.25,768.789 3148.15,769.851C3147.05,770.899 3147.01,772.644 3148.07,773.75C3152.77,778.654 3156.33,785.389 3158.64,793.768L3159.47,796.755Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> <g transform="matrix(1,0,0,1,-2908.03,-614.145)"> <path d="M3107.96,856.809L3141.33,856.809C3139.18,860.384 3133.01,863.493 3124.65,863.493C3116.28,863.493 3110.11,860.384 3107.96,856.809ZM3082.21,848.53C3082.3,847.855 3084.23,846.024 3085.5,844.818C3088.94,841.558 3093.63,837.106 3095.76,829.783C3098.23,821.224 3101.71,808.717 3104.68,797.954C3109.7,779.853 3119.25,779.989 3124.91,779.875C3129.95,779.91 3139.6,779.853 3144.61,797.954C3147.58,808.717 3151.06,821.217 3153.53,829.783C3155.66,837.106 3160.36,841.558 3163.79,844.818C3165.07,846.031 3167,847.862 3167.09,848.487C3167.09,848.487 3166.95,848.946 3166.06,849.65C3163.53,850.611 3148.55,851.154 3132.01,851.294L3115.28,851.294C3099.62,851.17 3085.84,850.686 3083.56,849.844C3082.39,848.989 3082.22,848.53 3082.21,848.53ZM3147.31,856.452C3158.82,856.057 3167.58,855.332 3169.01,854.281C3171.3,852.594 3172.47,850.82 3172.59,848.853C3172.78,845.744 3170.37,843.461 3167.59,840.812C3164.45,837.839 3160.54,834.134 3158.83,828.246C3156.36,819.709 3152.9,807.223 3149.92,796.489C3144.66,777.496 3134.12,774.771 3127.41,774.413L3127.41,766.563C3127.41,765.041 3126.17,763.806 3124.65,763.806C3123.13,763.806 3121.89,765.041 3121.89,766.563L3121.89,774.38C3115.39,774.642 3104.73,777.113 3099.37,796.489C3096.4,807.223 3092.93,819.702 3090.46,828.246C3088.76,834.134 3084.85,837.839 3081.71,840.818C3078.92,843.461 3076.51,845.744 3076.7,848.853C3076.82,850.813 3077.99,852.594 3080.28,854.281C3081.71,855.332 3090.47,856.057 3101.98,856.452C3103.71,863.65 3113,869.007 3124.65,869.007C3136.29,869.007 3145.58,863.65 3147.31,856.452Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/> </g> </svg>
flip an element inside SVG horizontally but keeps it's original position
I want to flip SVG elements (path, line, polyline, text ...) without changing the original position. For example <div id="canvas" style="width: 550px; height: 550px"> <svg version="1.2" baseProfile="tiny" id="Logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 250 250" xml:space="preserve"> <text id="text" transform="matrix(1 0 0 1 31.1271 199.1222)" fill="#561010" font-family="'Roboto-Regular'" font-size="25.3945px">Nom d’entreprise</text> <g> <linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="76.157" y1="87.0921" x2="70.9488" y2="44.8529"> <stop offset="0.0233" style="stop-color:#E92460"></stop> <stop offset="0.4636" style="stop-color:#F05C4B"></stop> <stop offset="0.9517" style="stop-color:#F36D38"></stop> </linearGradient> <path transform="matrix(1 0 0 1 0 0)" fill="url(#SVGID_2_)" d="M51.75,55.77c-0.27-0.39,3.97-5.2,10.38-7.74c1.79-0.71,11.97-4.75,21.31,0.8 c8.61,5.12,11.99,15.71,10.53,24.27c-2.38,13.95-17.76,23.37-22.24,20.72c-0.97-0.57-1.32-2.75-1.99-7.09 c-1.81-11.84-1.68-20.54-1.68-20.54c0.05-3.05,0.19-4.38-0.61-6.25c-1.42-3.32-4.9-6.23-8.62-6.47 C54.84,53.21,51.97,56.08,51.75,55.77z"></path> </g> </svg> </div> I tried various solution such as changing transform to matrix(-1 0 0 1 -100 0). Also I have tried to add attribute transform-origin="center". All I reached is a missplaced element. I have been trying the following: flipHorizontal(){ let viewBox_array = this.getViewBox(); // this returns ['0', '0', '250', '250'] let canvas_width = $("#canvas").width(); this.selectedElements.forEach(element =>{ let element_width = element.getBoundingClientRect().width element.setAttribute("transform-origin", "center") var matrix = element.transform.baseVal[0].matrix; matrix.a = (-1) * matrix.a let diff = (element_width / (canvas_width / Number(viewBox_array[2])) )* Math.sign(matrix.a); matrix.e += diff; }); this.edit_done(); } Also tried the following flipHorizontal(){ this.selectedElements.forEach(element =>{ element.setAttribute("transform-origin", "center") let bbox = element.getBBox(); var matrix = element.transform.baseVal[0].matrix; matrix.a = (-1) * matrix.a matrix.e += Math.sign(matrix.a) * (bbox.width + bbox.x); }); this.edit_done(); }
As detailed in my answer here, the transform functions needed to flip in place are: translate(<minX+maxX>,0) scale(-1, 1) So, a working version of your code, might look something like this: function flipHorizontal(selectedElements) { selectedElements.forEach(element => { // Get the bounds of the element let bbox = element.getBBox(); // Get the current transform attribute (if any) of the element let currentTransform = element.getAttribute("transform") || ""; // Append translate and scale functions to the transform that will flip the element in place element.setAttribute("transform", currentTransform + ' translate('+(bbox.x + bbox.x + bbox.width) + ',0) scale(-1, 1)'); }); } let elementsToFlip = document.querySelectorAll("path, text"); flipHorizontal( elementsToFlip ); <div id="canvas" style="width: 550px; height: 550px"> <svg version="1.2" baseProfile="tiny" id="Logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 250 250" xml:space="preserve"> <text id="text" transform="matrix(1 0 0 1 31.1271 199.1222)" fill="#561010" font-family="'Roboto-Regular'" font-size="25.3945px">Nom d’entreprise</text> <g> <linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="76.157" y1="87.0921" x2="70.9488" y2="44.8529"> <stop offset="0.0233" style="stop-color:#E92460"></stop> <stop offset="0.4636" style="stop-color:#F05C4B"></stop> <stop offset="0.9517" style="stop-color:#F36D38"></stop> </linearGradient> <path transform="matrix(1 0 0 1 0 0)" fill="url(#SVGID_2_)" d="M51.75,55.77c-0.27-0.39,3.97-5.2,10.38-7.74c1.79-0.71,11.97-4.75,21.31,0.8 c8.61,5.12,11.99,15.71,10.53,24.27c-2.38,13.95-17.76,23.37-22.24,20.72c-0.97-0.57-1.32-2.75-1.99-7.09 c-1.81-11.84-1.68-20.54-1.68-20.54c0.05-3.05,0.19-4.38-0.61-6.25c-1.42-3.32-4.9-6.23-8.62-6.47 C54.84,53.21,51.97,56.08,51.75,55.77z"></path> </g> </svg> </div>
You can do this with the only CSS, for example: .logo_text--flipped, .logo_image--flipped { transform-origin: center center; transform: scaleX(-1); } <div id="canvas" style="width: 550px; height: 550px"> <svg version="1.2" baseProfile="tiny" id="Logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 250 250" xml:space="preserve"> <g class="logo_text logo_text--flipped"> <text id="text" transform="matrix(1 0 0 1 31.1271 199.1222)" fill="#561010" font-family="'Roboto-Regular'" font-size="25.3945px">Nom d’entreprise</text> </g> <g class="logo_image logo_image--flipped"> <linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="76.157" y1="87.0921" x2="70.9488" y2="44.8529"> <stop offset="0.0233" style="stop-color:#E92460"></stop> <stop offset="0.4636" style="stop-color:#F05C4B"></stop> <stop offset="0.9517" style="stop-color:#F36D38"></stop> </linearGradient> <path transform="matrix(1 0 0 1 0 0)" fill="url(#SVGID_2_)" d="M51.75,55.77c-0.27-0.39,3.97-5.2,10.38-7.74c1.79-0.71,11.97-4.75,21.31,0.8 c8.61,5.12,11.99,15.71,10.53,24.27c-2.38,13.95-17.76,23.37-22.24,20.72c-0.97-0.57-1.32-2.75-1.99-7.09 c-1.81-11.84-1.68-20.54-1.68-20.54c0.05-3.05,0.19-4.38-0.61-6.25c-1.42-3.32-4.9-6.23-8.62-6.47 C54.84,53.21,51.97,56.08,51.75,55.77z"></path> </g> </svg> </div> So you can create a specific class and toggle it via JS
How use svg or qml shapes for template on my application
I want to create an application for dispaly poem and I want to use Eslimi arts for frame or template to display these peoms .an example of Eslimi are in this page and here .But I have a problem with multiple screen size on mobile and desktops,For example I deployed my app on some are good but on and some are small because I use jpg file of these arts,So the jpg file could not adjust himself for be taller or wider.So I decided to pars these svg files to multiple parts and make them display progammatically aroud the poems.Untile In Shapes Example there is a Tiger.qml file like below import QtQuick 2.12 import QtQuick.Shapes 1.12 Shape { asynchronous: true width: 494; height: 510 ShapePath { fillColor: "#ffffff" strokeColor: "#000000" strokeWidth: 0.172 PathMove { x: -122.304; y: 84.285 } PathCubic { control1X: -122.304; control1Y: 84.285; control2X: -122.203; control2Y: 86.179; x: -123.027; y: 86.16 } PathCubic { control1X: -123.851; control1Y: 86.141; control2X: -140.305; control2Y: 38.066; x: -160.833; y: 40.309 } PathCubic { control1X: -160.833; control1Y: 40.309; control2X: -143.05; control2Y: 32.956; x: -122.304; y: 84.285 } } } Now I have a svg file like this, <?xml version="1.0" encoding="utf-8"?> <!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"> <style type="text/css"> .st0{fill:#282F68;} .st1{fill:#FFFFFF;} .st2{fill:#91D0D5;} </style> <g> <g> <path class="st0" d="M474.1,130.5c-56.1,11.6-103.7-45.8-157,21.2C348.5,72.1,274.8,59.4,256.7,5c-0.2,0.6-0.5,1.2-0.7,1.8 c-0.2-0.6-0.5-1.1-0.7-1.8c-18.1,54.4-91.7,67-60.3,146.7c-53.4-67-101-9.7-157-21.2c38,42.8,12,113.1,96.7,125.7 C50,268.9,76,338.7,37.9,381.5c56.1-11.5,103.7,46.2,157-20.8c-31.4,79.7,42.2,92,60.3,146.3c0.2-0.6,0.5-1.2,0.7-1.8 c0.2,0.6,0.5,1.1,0.7,1.8c18.1-54.4,91.7-66.6,60.3-146.3c53.3,67,101,9.3,157,20.8c-38-42.8-12-112.6-96.7-125.2 C462,243.6,436,173.3,474.1,130.5z"/> <g> <path class="st1" d="M255.3,162.2c0.3-0.1,0.4-0.3,0.7-0.4c0.3,0.1,0.4,0.3,0.7,0.4c42.5-19,34.2-57.3,0-92.6 c-0.3,0.3-0.5,0.6-0.7,0.9c-0.3-0.3-0.5-0.6-0.7-0.9C221.1,104.9,212.8,143.2,255.3,162.2z"/> <path class="st1" d="M93.6,162.9c13.5,47.2,42.5,73.5,80.2,46.3C178.6,162.9,141.2,150.9,93.6,162.9z"/> <path class="st1" d="M93.6,349.5c47.6,12,85,0,80.2-46.3C136.1,276,107.1,302.3,93.6,349.5z"/> <path class="st1" d="M338.2,303.3c-4.8,46.2,32.6,58.2,80.2,46.3C404.9,302.3,375.9,276,338.2,303.3z"/> <path class="st1" d="M256.8,350.2c-0.3,0.1-0.5,0.3-0.8,0.5c-0.3-0.2-0.5-0.3-0.8-0.5c-42.5,19-34.2,57.4,0,92.6 c0.3-0.3,0.5-0.6,0.8-0.9c0.3,0.3,0.5,0.6,0.8,0.9C291,407.6,299.3,369.2,256.8,350.2z"/> <path class="st1" d="M338.2,209.1c37.7,27.3,66.7,1,80.2-46.3C370.8,150.9,333.4,162.9,338.2,209.1z"/> </g> </g> <g> <g> <path class="st2" d="M310.3,284.4c17,28.4-33.1,57.4-49.2,28.4c-0.2,0.3-0.5,0.5-0.7,0.8c-0.2-0.3-0.5-0.4-0.7-0.8 c-16.1,29-66.2-0.1-49.2-28.4c-33.1,0.5-33.1-57.3,0-56.8c-16.9-28.4,33.1-57.3,49.2-28.3c0.2-0.3,0.5-0.5,0.7-0.8 c0.2,0.3,0.5,0.5,0.7,0.8c16.2-29,66.2-0.1,49.2,28.3C343.4,227,343.4,284.9,310.3,284.4z"/> </g> <path class="st1" d="M287.4,256c0-18-13.5-27.1-27-27.1c-13.5,0.1-27,9.1-27,27.1c0,18,13.5,27.1,27,27.1 C273.9,283.1,287.4,274,287.4,256z"/> </g> </g> </svg> This svg file is a simplified of complex svg file .So I don't know how do the works.Shold I convert svg to qml shapes? shoudl I convert svg to qquickitem? or what? Does any one know How Should I work this?
Why my SVG do not take the expected color?
I have created an animated text, it works with SVG PATH and MASK. The thing is that I do not understand why I can not fill it up in white :/ I tried to use fill attribut or stroke ... After all I did it has nothing to do. It's very weird, do you know why it does not take the color has expected ? Someone has a solution or an idea on how to make it white ? body { background-color: red; } mask path { fill: none; stroke: white; stroke-width: 20; } #maskH path, #maskH2 path { stroke-dasharray: 500; stroke-dashoffset: 500; animation: brush 2s linear 1 forwards; stroke-width: 19.5; } #maskI path, #maskT path, #maskT2 path, #maskF path, #maskU path, #maskU2 path, #maskE path, #maskE2 path, #maskG path, #maskR path, #maskS path, #maskT2 path, #maskA path, #maskN path, #maskP path, #maskT path { stroke-dasharray: 500; stroke-dashoffset: 500; animation: brush 3s linear 1 forwards; stroke-width: 19.5; } #maskT path { stroke-width: 9.6; } #maskT2 path { stroke-width: 9.8; } #maskA path { stroke-width: 18; } #maskP path { stroke-width: 19.4; } #maskN path { stroke-width: 20; } #keyframes brush { 0% { stroke-dashoffset: 500; } 20% { stroke-dashoffset: 500; } 80% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: 0; } } <svg height="300px" width="900px" id="FlorianCargouet" data-name="byflo-io" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1107.2 69.56"> <mask id="maskS"> <path d="M73.9,30.26c-16.7-8.75-32.61-7.37-38.23,0.48c-3.28,4.58-4.06,12.76-0.44,17.78c1.5,2.07,3.31,3.01,13.03,6.19 c16.47,5.39,20.71,5.81,23.08,10.01c2.02,3.6,1.68,8.22,0.18,11.47c-1.89,4.08-5.57,5.92-7.45,6.85 c-12.88,6.41-34.08-3.11-36.75-4.34" /> </mask> <mask id="maskH"> <path d="M92.2,22.2 92.2,89.5 92.2,16.5 150.2,16.5 150.2,89.5 90.6,81.4 90.6,54.8 153.2,54.8 " /> </mask> <mask id="maskA"> <path d="M160.4,89.6 189.9,23.8 200.8,23.8 231.2,89.6 226.1,67.1 172.7,67.4 " /> </mask> <mask id="maskP"> <path d="M241.4,21.9 241.4,89.5 228.7,22.1 275.5,22.6 281.6,24 286.2,26.4 290.6,30.2 293.3,34 295.5,39.9 296.1,45.3 296,48.4 295.3,51.9 294,55.6 292.1,59 289.6,61.8 286.2,64.5 281.9,66.8 277.5,68 272,68.8 251.1,69.1 " /> </mask> <mask id="maskI"> <path d="M315,22.1 315,55.8 315,89.5 " /> </mask> <mask id="maskN"> <path d="M340.2,89.4 340.2,21.9 350,39.5 389.5,88.5 391.1,89.6 398.3,89.6 398.3,22.1 388.4,22.1 347.3,22 " /> </mask> <mask id="maskT"> <path d="M537.5,22.1 537.5,89.5 497.3,26.5 565.4,26.5 " /> </mask> <mask id="maskT2"> <path d="M900.3,22.1 900.3,90.2 863.5,26.3 929.1,26.3 " /> </mask> <mask id="maskH2"> <!-- <path d="M576.1,22.1 576.1,89.5 563.7,55.8 622.1,54.7 605.2,53.1 605.2,14.3 629.6,14.3 629.6,89.5 " /> --> <path d="M576.1,22.1c0,22.5,0,44.9,0,67.4V12.2h58.1v77.3l-61.9-8.4V54.8h64.5" /> </mask> <mask id="maskF"> <path d="M794.4,22.1 745.4,22.1 745.4,89.5 741.7,53.8 788.7,53.8 " /> </mask> <mask id="maskU"> <path d="M806,22c0.2,21.2,0.4,36.3,0.4,40.4c0,0.4,0,1.8,0.2,3.7c0.2,1.9,0.4,4.4,1.5,7.4c0.8,2.2,1.7,3.8,2,4.3 c0.9,1.6,1.8,2.7,2.4,3.4c0.6,0.8,1.9,2.2,3.8,3.6c0.5,0.4,2.2,1.6,4.7,2.8c3.1,1.4,5.8,1.9,7.6,2.2c1.5,0.3,5,0.8,9.4,0.4 c3.6-0.3,6.1-1,6.7-1.2c1.7-0.5,4.1-1.2,6.8-2.8c2.3-1.4,3.7-2.8,4.2-3.2c0.6-0.5,2.3-2.4,3.9-5.3c0.3-0.5,1.4-2.6,2.4-6.4 c0.8-3.2,1.2-6,1.4-9.7c0.4-6.6,0.2-11.5,0.2-11.5c-0.3-5.4-0.4-14-0.2-28.2" /> </mask> <mask id="maskU2"> <path d="M936.5,21.8c0.2,21.2,0.4,36.3,0.4,40.4c0,0.4,0,1.8,0.2,3.7c0.2,1.9,0.4,4.4,1.5,7.4c0.8,2.2,1.7,3.8,2,4.3 c0.9,1.6,1.8,2.7,2.4,3.4c0.6,0.8,1.9,2.2,3.8,3.6c0.5,0.4,2.2,1.6,4.7,2.8c3.1,1.4,5.8,1.9,7.6,2.2c1.5,0.3,5,0.8,9.4,0.4 c3.6-0.3,6.1-1,6.7-1.2c1.7-0.5,4.1-1.2,6.8-2.8c2.3-1.4,3.7-2.8,4.2-3.2c0.6-0.5,2.3-2.4,3.9-5.3c0.3-0.5,1.4-2.6,2.4-6.4 c0.8-3.2,1.2-6,1.4-9.7c0.4-6.6,0.2-11.5,0.2-11.5c-0.3-5.4-0.4-14-0.2-28.2" /> </mask> <mask id="maskE"> <path d="M702.2,22.1 654.6,22.1 654.6,89.5 703.6,89.5 650,89.5 664.4,59.4 698,59.4 " /> </mask> <mask id="maskE2"> <path d="M1131.9,22.1 1084.3,22.1 1084.3,89.5 1133.3,89.5 1079.7,89.5 1094.1,59.4 1127.7,59.4 " /> </mask> <mask id="maskG"> <path d="M475.4,31.4c-1.1-1.1-2.6-2.5-4.7-4c-6.6-4.7-13.2-5.7-15.9-6.1c-2.5-0.4-8.8-1-16.4,1.2 c-3.1,0.9-9.3,2.8-15.1,8.3c-1.5,1.4-4.6,4.6-7.1,9.7c-0.7,1.4-2.2,4.9-3,9.7c-1.2,7.6,0.4,13.7,1.1,15.9c1.7,5.5,4.4,9.2,5.8,11.1 c2,2.5,5.4,6.2,10.8,9.1c6.6,3.5,12.6,3.9,16.2,4.1c8.1,0.4,14.2-1.6,16.1-2.3c7-2.5,9.2-3.6,10.3-5.5c0.9-1.6,1.1-3.1,1.2-5.3 c0.3-4.7,0.3-7.9,0-15.6c-0.2-3.8-0.2-4.2-0.2-6.2c0-2.6,0.1-4.7,0.2-6.1" /> </mask> <mask id="maskR"> <path d="M1014.1,21.4l0,68l-1-59.2c11.7,0.4,19.8,0.6,24.6,0.4c0,0,3.9-0.2,9.9,0.8c0.9,0.1,2.2,0.4,3.7,1.1 c0.8,0.4,2.7,1.4,4.3,3.4c2.3,2.8,2.8,5.8,3,7.4c0.6,4.3-0.6,7.8-1.4,9.4l-1.2,2l-2.6,2.6l-12.4,3.3l-17.2,0.1l20.5,8.5l0.6,0.4 l0.8,0.9l12.2,17.3l1.2,1.3l1.6,0.4l2.8,0l6.3,0" /> </mask> <path mask="url(#maskN)" d="M340.18,21.91c2.5,0,4.84-.15,7.13.08.8.08,1.64,1,2.23,1.71q18.6,23,37.15,46.13c.41.51.87,1,1.73,2V22.1h9.85V89.63c-2.4,0-4.8.15-7.15-.08-.8-.08-1.64-1-2.23-1.73q-18.28-22.65-36.51-45.36l-2.41-3V89.43h-9.78C340.18,67.07,340.18,44.71,340.18,21.91Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskR)" d="M1014.06,21.39c12.23.53,24.39-.18,36.08,1.83,20.18,3.47,22,24.38,14.8,35.43-2.6,4-6.38,6.48-11.1,8.3l7.92,11.25,8,11.44c-3.64,0-6.75.08-9.86-.07-.63,0-1.37-.81-1.81-1.42-4.16-5.83-8.24-11.71-12.4-17.53-.48-.67-1.32-1.52-2-1.54-6.56-.12-13.12-.07-20-.07V89.52h-9.68C1014.06,67.05,1014.06,44.63,1014.06,21.39Zm9.84,8.78V60.7c4.79,0,9.36.08,13.92,0A59.93,59.93,0,0,0,1047,60c7.5-1.37,11.87-6.83,11.85-14.43s-4.28-13.37-11.89-14.29S1031.75,30.49,1023.9,30.17Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskH)" d="M150.16,89.53h-9.67V59.69H102V89.44H92.1V22.11h9.68V50.85h38.54V22.1h9.84Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskH2)" d="M634.23,89.53h-9.68V59.69h-38.7V89.51h-9.7V22.06h9.62V50.79H624.4V22.08h9.83Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskE)" d="M702.29,22.12V30.4H664.46V50.93H698v8.49H664.46V81h39.08v8.54H654.6V22.11Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskE2)" d="M1084.35,89.46V22.07h47.55v8.27h-37.76V51h33.62v8.36h-33.59V81h39.15v8.42Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskG)" d="M465.42,55.44h9.21a8,8,0,0,1,.28,1.48c0,7.75.09,15.49-.07,23.24A4.61,4.61,0,0,1,473,83.28a40.36,40.36,0,0,1-22.76,7.15c-12,.16-22.33-3.62-29.91-13.24C405.43,58.32,413.55,27.36,440.8,22c10.94-2.15,21.4-.92,30.67,5.93,1.38,1,2.6,2.27,4,3.49l-6.23,5.92a28.06,28.06,0,0,0-14.08-7c-15.81-2.43-28.82,5.55-31.8,20.19C419.92,67.37,432.5,82,450.13,81.63a32.28,32.28,0,0,0,13.05-2.9,3.35,3.35,0,0,0,2.29-3.58C465.35,68.68,465.42,62.2,465.42,55.44Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskP)" d="M241.44,21.9c3.73,0,7.3-.06,10.86,0,7.74.16,15.54-.16,23.2.72,10.68,1.23,18,8,19.95,17.26,3.12,14.61-5.19,26.62-20.36,28.58-6.57.85-13.3.49-19.95.67-1.24,0-2.48,0-4.06,0V89.49h-9.64Zm9.76,8.28V60.45c6.85,0,13.51.18,20.16-.07a16,16,0,0,0,10.12-3.76c4.9-4.31,5.55-9.85,4.06-15.77s-5.88-9-11.5-9.64C266.54,30.4,259,30.49,251.2,30.18Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskA)" d="M231.22,89.64c-3.31,0-6.14.12-8.95-.08a3.11,3.11,0,0,1-2-1.71c-2-4.37-4-8.78-5.84-13.24a2.73,2.73,0,0,0-3-1.93c-10.5.07-21,.1-31.49,0-1.85,0-2.62.71-3.27,2.28-1.78,4.3-3.79,8.51-5.55,12.82a2.62,2.62,0,0,1-3,1.89c-2.49-.13-5,0-7.75,0,.26-.81.4-1.42.65-2Q175.52,55.71,190,23.77c.65-1.43,1.55-1.69,3-1.95,5.88-1,8.57,1.55,10.89,6.93,8.38,19.48,17.39,38.69,26.16,58C230.37,87.57,230.7,88.4,231.22,89.64Zm-21.1-24.8L195.65,32,181.21,64.84Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskU)" d="M806,22h9.9v3.27c0,11.58-.08,23.15,0,34.73a42.2,42.2,0,0,0,1.13,9.37c1.21,5,4.14,8.92,9.15,10.77a23.2,23.2,0,0,0,17.3-.1c8.29-3.42,10.18-10.7,10.3-18.62.19-12.16,0-24.32.06-36.48V22.07h9.43c0,.9.12,1.71.12,2.52,0,12.41.18,24.82-.1,37.22a41.8,41.8,0,0,1-2.22,12.44c-2.64,7.64-8.24,12.58-16,14.8a37.77,37.77,0,0,1-19.74.25c-11-2.76-18.3-11.41-18.88-23.58-.63-13.13-.34-26.3-.45-39.46C806,25,806,23.64,806,22Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskU2)" d="M936.85,22h9.74v2.8c0,11.91-.06,23.83,0,35.74,0,5.2.68,10.38,4,14.67A13.86,13.86,0,0,0,955,79.16c7.25,3.64,14.65,3.67,21.72-.37,5.24-3,7.23-8.26,7.54-13.92.43-7.81.33-15.65.39-23.48,0-5.66,0-11.33,0-17,0-.73.08-1.46.14-2.34h9.06a4.71,4.71,0,0,1,.24,1c0,13.91.3,27.84-.27,41.73-.62,15.18-10.06,24.51-25.16,25.35a43,43,0,0,1-14.27-1.4c-10.11-3-15.37-10.57-17-20.76a45.71,45.71,0,0,1-.56-7.21c-.05-12.16,0-24.33,0-36.49C936.85,23.61,936.85,23,936.85,22Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskS)" d="M71.77,34.74c-6.56-3.74-13.5-5.86-21-5.1a28.51,28.51,0,0,0-8.16,2A8.81,8.81,0,0,0,37,40.08a7.85,7.85,0,0,0,5.36,7.71c4.31,1.7,8.84,2.84,13.29,4.19,3.18,1,6.42,1.75,9.55,2.86C73.87,57.91,78,63.15,78,71c0,8-4.61,14.68-12.93,17.35-12.91,4.16-25.29,2.42-37-4.46-1.85-1.09-2.65-2.26-1.27-4.35A36.43,36.43,0,0,0,29,75.05c.07-.13.24-.22.5-.45A36.06,36.06,0,0,0,44,81.23c5.87,1.15,11.74,1.4,17.49-.62,3.93-1.38,6.51-4,6.85-8.32s-2.18-7.17-5.92-8.58c-4.42-1.66-9-2.75-13.58-4.09-2.79-.83-5.61-1.56-8.36-2.51C31.62,54,27.42,48.69,27.39,40.65s4.74-14.82,13.1-17.52c11.2-3.62,22.16-2.49,32.73,2.67,1.54.75,2.12,1.6,1.24,3.29S73,32.45,72.31,34.14A5.75,5.75,0,0,1,71.77,34.74Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskF)" d="M793.13,22.06c0,2.42,0,4.73,0,7,0,1.77-1.37,1.35-2.36,1.35q-16.24,0-32.48,0h-3.11V53.8h33.61v8.48H755.05V89.47h-9.56V22.06Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskT2)" d="M895.3,30.5c-7.9,0-15.4,0-23.1,0c0-2.9,0-5.6,0-8.4c18.6,0,37.1,0,55.8,0c0,2.8,0,5.4,0,8.4 c-7.6,0-15.1,0-23,0c0,19.8,0,39.4,0,59.1c-3.3,0-6.4,0-9.7,0C895.3,70,895.3,50.4,895.3,30.5z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskT)" d="M532.76,30.45H509.64V22h55.77v8.35H542.46V89.47h-9.71C532.76,69.9,532.76,50.37,532.76,30.45Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskI)" d="M319.76,89.53H310.2V22.1h9.56Z" transform="translate(-26.12 -21.02)" /> </svg>
To your code I'm adding [mask]{fill:white} meaning that I'm filling with white the paths with a mask attribute. [mask]{fill:white} body { background-color: red; } mask path { fill: none; stroke: white; stroke-width: 20; } #maskH path, #maskH2 path { stroke-dasharray: 500; stroke-dashoffset: 500; animation: brush 2s linear 1 forwards; stroke-width: 19.5; } #maskI path, #maskT path, #maskT2 path, #maskF path, #maskU path, #maskU2 path, #maskE path, #maskE2 path, #maskG path, #maskR path, #maskS path, #maskT2 path, #maskA path, #maskN path, #maskP path, #maskT path { stroke-dasharray: 500; stroke-dashoffset: 500; animation: brush 3s linear 1 forwards; stroke-width: 19.5; } #maskT path { stroke-width: 9.6; } #maskT2 path { stroke-width: 9.8; } #maskA path { stroke-width: 18; } #maskP path { stroke-width: 19.4; } #maskN path { stroke-width: 20; } #keyframes brush { 0% { stroke-dashoffset: 500; } 20% { stroke-dashoffset: 500; } 80% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: 0; } } <svg height="300px" width="900px" id="FlorianCargouet" data-name="byflo-io" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1107.2 69.56"> <mask id="maskS"> <path d="M73.9,30.26c-16.7-8.75-32.61-7.37-38.23,0.48c-3.28,4.58-4.06,12.76-0.44,17.78c1.5,2.07,3.31,3.01,13.03,6.19 c16.47,5.39,20.71,5.81,23.08,10.01c2.02,3.6,1.68,8.22,0.18,11.47c-1.89,4.08-5.57,5.92-7.45,6.85 c-12.88,6.41-34.08-3.11-36.75-4.34" /> </mask> <mask id="maskH"> <path d="M92.2,22.2 92.2,89.5 92.2,16.5 150.2,16.5 150.2,89.5 90.6,81.4 90.6,54.8 153.2,54.8 " /> </mask> <mask id="maskA"> <path d="M160.4,89.6 189.9,23.8 200.8,23.8 231.2,89.6 226.1,67.1 172.7,67.4 " /> </mask> <mask id="maskP"> <path d="M241.4,21.9 241.4,89.5 228.7,22.1 275.5,22.6 281.6,24 286.2,26.4 290.6,30.2 293.3,34 295.5,39.9 296.1,45.3 296,48.4 295.3,51.9 294,55.6 292.1,59 289.6,61.8 286.2,64.5 281.9,66.8 277.5,68 272,68.8 251.1,69.1 " /> </mask> <mask id="maskI"> <path d="M315,22.1 315,55.8 315,89.5 " /> </mask> <mask id="maskN"> <path d="M340.2,89.4 340.2,21.9 350,39.5 389.5,88.5 391.1,89.6 398.3,89.6 398.3,22.1 388.4,22.1 347.3,22 " /> </mask> <mask id="maskT"> <path d="M537.5,22.1 537.5,89.5 497.3,26.5 565.4,26.5 " /> </mask> <mask id="maskT2"> <path d="M900.3,22.1 900.3,90.2 863.5,26.3 929.1,26.3 " /> </mask> <mask id="maskH2"> <!-- <path d="M576.1,22.1 576.1,89.5 563.7,55.8 622.1,54.7 605.2,53.1 605.2,14.3 629.6,14.3 629.6,89.5 " /> --> <path d="M576.1,22.1c0,22.5,0,44.9,0,67.4V12.2h58.1v77.3l-61.9-8.4V54.8h64.5" /> </mask> <mask id="maskF"> <path d="M794.4,22.1 745.4,22.1 745.4,89.5 741.7,53.8 788.7,53.8 " /> </mask> <mask id="maskU"> <path d="M806,22c0.2,21.2,0.4,36.3,0.4,40.4c0,0.4,0,1.8,0.2,3.7c0.2,1.9,0.4,4.4,1.5,7.4c0.8,2.2,1.7,3.8,2,4.3 c0.9,1.6,1.8,2.7,2.4,3.4c0.6,0.8,1.9,2.2,3.8,3.6c0.5,0.4,2.2,1.6,4.7,2.8c3.1,1.4,5.8,1.9,7.6,2.2c1.5,0.3,5,0.8,9.4,0.4 c3.6-0.3,6.1-1,6.7-1.2c1.7-0.5,4.1-1.2,6.8-2.8c2.3-1.4,3.7-2.8,4.2-3.2c0.6-0.5,2.3-2.4,3.9-5.3c0.3-0.5,1.4-2.6,2.4-6.4 c0.8-3.2,1.2-6,1.4-9.7c0.4-6.6,0.2-11.5,0.2-11.5c-0.3-5.4-0.4-14-0.2-28.2" /> </mask> <mask id="maskU2"> <path d="M936.5,21.8c0.2,21.2,0.4,36.3,0.4,40.4c0,0.4,0,1.8,0.2,3.7c0.2,1.9,0.4,4.4,1.5,7.4c0.8,2.2,1.7,3.8,2,4.3 c0.9,1.6,1.8,2.7,2.4,3.4c0.6,0.8,1.9,2.2,3.8,3.6c0.5,0.4,2.2,1.6,4.7,2.8c3.1,1.4,5.8,1.9,7.6,2.2c1.5,0.3,5,0.8,9.4,0.4 c3.6-0.3,6.1-1,6.7-1.2c1.7-0.5,4.1-1.2,6.8-2.8c2.3-1.4,3.7-2.8,4.2-3.2c0.6-0.5,2.3-2.4,3.9-5.3c0.3-0.5,1.4-2.6,2.4-6.4 c0.8-3.2,1.2-6,1.4-9.7c0.4-6.6,0.2-11.5,0.2-11.5c-0.3-5.4-0.4-14-0.2-28.2" /> </mask> <mask id="maskE"> <path d="M702.2,22.1 654.6,22.1 654.6,89.5 703.6,89.5 650,89.5 664.4,59.4 698,59.4 " /> </mask> <mask id="maskE2"> <path d="M1131.9,22.1 1084.3,22.1 1084.3,89.5 1133.3,89.5 1079.7,89.5 1094.1,59.4 1127.7,59.4 " /> </mask> <mask id="maskG"> <path d="M475.4,31.4c-1.1-1.1-2.6-2.5-4.7-4c-6.6-4.7-13.2-5.7-15.9-6.1c-2.5-0.4-8.8-1-16.4,1.2 c-3.1,0.9-9.3,2.8-15.1,8.3c-1.5,1.4-4.6,4.6-7.1,9.7c-0.7,1.4-2.2,4.9-3,9.7c-1.2,7.6,0.4,13.7,1.1,15.9c1.7,5.5,4.4,9.2,5.8,11.1 c2,2.5,5.4,6.2,10.8,9.1c6.6,3.5,12.6,3.9,16.2,4.1c8.1,0.4,14.2-1.6,16.1-2.3c7-2.5,9.2-3.6,10.3-5.5c0.9-1.6,1.1-3.1,1.2-5.3 c0.3-4.7,0.3-7.9,0-15.6c-0.2-3.8-0.2-4.2-0.2-6.2c0-2.6,0.1-4.7,0.2-6.1" /> </mask> <mask id="maskR"> <path d="M1014.1,21.4l0,68l-1-59.2c11.7,0.4,19.8,0.6,24.6,0.4c0,0,3.9-0.2,9.9,0.8c0.9,0.1,2.2,0.4,3.7,1.1 c0.8,0.4,2.7,1.4,4.3,3.4c2.3,2.8,2.8,5.8,3,7.4c0.6,4.3-0.6,7.8-1.4,9.4l-1.2,2l-2.6,2.6l-12.4,3.3l-17.2,0.1l20.5,8.5l0.6,0.4 l0.8,0.9l12.2,17.3l1.2,1.3l1.6,0.4l2.8,0l6.3,0" /> </mask> <path mask="url(#maskN)" d="M340.18,21.91c2.5,0,4.84-.15,7.13.08.8.08,1.64,1,2.23,1.71q18.6,23,37.15,46.13c.41.51.87,1,1.73,2V22.1h9.85V89.63c-2.4,0-4.8.15-7.15-.08-.8-.08-1.64-1-2.23-1.73q-18.28-22.65-36.51-45.36l-2.41-3V89.43h-9.78C340.18,67.07,340.18,44.71,340.18,21.91Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskR)" d="M1014.06,21.39c12.23.53,24.39-.18,36.08,1.83,20.18,3.47,22,24.38,14.8,35.43-2.6,4-6.38,6.48-11.1,8.3l7.92,11.25,8,11.44c-3.64,0-6.75.08-9.86-.07-.63,0-1.37-.81-1.81-1.42-4.16-5.83-8.24-11.71-12.4-17.53-.48-.67-1.32-1.52-2-1.54-6.56-.12-13.12-.07-20-.07V89.52h-9.68C1014.06,67.05,1014.06,44.63,1014.06,21.39Zm9.84,8.78V60.7c4.79,0,9.36.08,13.92,0A59.93,59.93,0,0,0,1047,60c7.5-1.37,11.87-6.83,11.85-14.43s-4.28-13.37-11.89-14.29S1031.75,30.49,1023.9,30.17Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskH)" d="M150.16,89.53h-9.67V59.69H102V89.44H92.1V22.11h9.68V50.85h38.54V22.1h9.84Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskH2)" d="M634.23,89.53h-9.68V59.69h-38.7V89.51h-9.7V22.06h9.62V50.79H624.4V22.08h9.83Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskE)" d="M702.29,22.12V30.4H664.46V50.93H698v8.49H664.46V81h39.08v8.54H654.6V22.11Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskE2)" d="M1084.35,89.46V22.07h47.55v8.27h-37.76V51h33.62v8.36h-33.59V81h39.15v8.42Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskG)" d="M465.42,55.44h9.21a8,8,0,0,1,.28,1.48c0,7.75.09,15.49-.07,23.24A4.61,4.61,0,0,1,473,83.28a40.36,40.36,0,0,1-22.76,7.15c-12,.16-22.33-3.62-29.91-13.24C405.43,58.32,413.55,27.36,440.8,22c10.94-2.15,21.4-.92,30.67,5.93,1.38,1,2.6,2.27,4,3.49l-6.23,5.92a28.06,28.06,0,0,0-14.08-7c-15.81-2.43-28.82,5.55-31.8,20.19C419.92,67.37,432.5,82,450.13,81.63a32.28,32.28,0,0,0,13.05-2.9,3.35,3.35,0,0,0,2.29-3.58C465.35,68.68,465.42,62.2,465.42,55.44Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskP)" d="M241.44,21.9c3.73,0,7.3-.06,10.86,0,7.74.16,15.54-.16,23.2.72,10.68,1.23,18,8,19.95,17.26,3.12,14.61-5.19,26.62-20.36,28.58-6.57.85-13.3.49-19.95.67-1.24,0-2.48,0-4.06,0V89.49h-9.64Zm9.76,8.28V60.45c6.85,0,13.51.18,20.16-.07a16,16,0,0,0,10.12-3.76c4.9-4.31,5.55-9.85,4.06-15.77s-5.88-9-11.5-9.64C266.54,30.4,259,30.49,251.2,30.18Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskA)" d="M231.22,89.64c-3.31,0-6.14.12-8.95-.08a3.11,3.11,0,0,1-2-1.71c-2-4.37-4-8.78-5.84-13.24a2.73,2.73,0,0,0-3-1.93c-10.5.07-21,.1-31.49,0-1.85,0-2.62.71-3.27,2.28-1.78,4.3-3.79,8.51-5.55,12.82a2.62,2.62,0,0,1-3,1.89c-2.49-.13-5,0-7.75,0,.26-.81.4-1.42.65-2Q175.52,55.71,190,23.77c.65-1.43,1.55-1.69,3-1.95,5.88-1,8.57,1.55,10.89,6.93,8.38,19.48,17.39,38.69,26.16,58C230.37,87.57,230.7,88.4,231.22,89.64Zm-21.1-24.8L195.65,32,181.21,64.84Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskU)" d="M806,22h9.9v3.27c0,11.58-.08,23.15,0,34.73a42.2,42.2,0,0,0,1.13,9.37c1.21,5,4.14,8.92,9.15,10.77a23.2,23.2,0,0,0,17.3-.1c8.29-3.42,10.18-10.7,10.3-18.62.19-12.16,0-24.32.06-36.48V22.07h9.43c0,.9.12,1.71.12,2.52,0,12.41.18,24.82-.1,37.22a41.8,41.8,0,0,1-2.22,12.44c-2.64,7.64-8.24,12.58-16,14.8a37.77,37.77,0,0,1-19.74.25c-11-2.76-18.3-11.41-18.88-23.58-.63-13.13-.34-26.3-.45-39.46C806,25,806,23.64,806,22Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskU2)" d="M936.85,22h9.74v2.8c0,11.91-.06,23.83,0,35.74,0,5.2.68,10.38,4,14.67A13.86,13.86,0,0,0,955,79.16c7.25,3.64,14.65,3.67,21.72-.37,5.24-3,7.23-8.26,7.54-13.92.43-7.81.33-15.65.39-23.48,0-5.66,0-11.33,0-17,0-.73.08-1.46.14-2.34h9.06a4.71,4.71,0,0,1,.24,1c0,13.91.3,27.84-.27,41.73-.62,15.18-10.06,24.51-25.16,25.35a43,43,0,0,1-14.27-1.4c-10.11-3-15.37-10.57-17-20.76a45.71,45.71,0,0,1-.56-7.21c-.05-12.16,0-24.33,0-36.49C936.85,23.61,936.85,23,936.85,22Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskS)" d="M71.77,34.74c-6.56-3.74-13.5-5.86-21-5.1a28.51,28.51,0,0,0-8.16,2A8.81,8.81,0,0,0,37,40.08a7.85,7.85,0,0,0,5.36,7.71c4.31,1.7,8.84,2.84,13.29,4.19,3.18,1,6.42,1.75,9.55,2.86C73.87,57.91,78,63.15,78,71c0,8-4.61,14.68-12.93,17.35-12.91,4.16-25.29,2.42-37-4.46-1.85-1.09-2.65-2.26-1.27-4.35A36.43,36.43,0,0,0,29,75.05c.07-.13.24-.22.5-.45A36.06,36.06,0,0,0,44,81.23c5.87,1.15,11.74,1.4,17.49-.62,3.93-1.38,6.51-4,6.85-8.32s-2.18-7.17-5.92-8.58c-4.42-1.66-9-2.75-13.58-4.09-2.79-.83-5.61-1.56-8.36-2.51C31.62,54,27.42,48.69,27.39,40.65s4.74-14.82,13.1-17.52c11.2-3.62,22.16-2.49,32.73,2.67,1.54.75,2.12,1.6,1.24,3.29S73,32.45,72.31,34.14A5.75,5.75,0,0,1,71.77,34.74Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskF)" d="M793.13,22.06c0,2.42,0,4.73,0,7,0,1.77-1.37,1.35-2.36,1.35q-16.24,0-32.48,0h-3.11V53.8h33.61v8.48H755.05V89.47h-9.56V22.06Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskT2)" d="M895.3,30.5c-7.9,0-15.4,0-23.1,0c0-2.9,0-5.6,0-8.4c18.6,0,37.1,0,55.8,0c0,2.8,0,5.4,0,8.4 c-7.6,0-15.1,0-23,0c0,19.8,0,39.4,0,59.1c-3.3,0-6.4,0-9.7,0C895.3,70,895.3,50.4,895.3,30.5z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskT)" d="M532.76,30.45H509.64V22h55.77v8.35H542.46V89.47h-9.71C532.76,69.9,532.76,50.37,532.76,30.45Z" transform="translate(-26.12 -21.02)" /> <path mask="url(#maskI)" d="M319.76,89.53H310.2V22.1h9.56Z" transform="translate(-26.12 -21.02)" /> </svg>
change svg title position and font size
I am using the SVG title tag to create tooltips for multiple svg elements (recs, polygons, etc.). However, the title element creates a small tooltip which is half covered by the mouse cursor. I have attempted to use CSS to change the title font size, but to no avail. I have searched for other ways to create the tooltips, but they involve changing the basic layout of my svg (creating multiple g elements for each element on my map). Is there a way to edit the title style? Thank you. This is the complete html file (excluding the basic layer map, as it contains too many characters to be displayed and there is nothing to edit there anyway): <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> <style> .copier:hover { fill:rgb(32, 43, 228); fill-opacity:0.7; pointer-events:all; } .copier { fill:rgb(32, 43, 228); fill-opacity:0.4; pointer-events:all; } .area:hover { fill:rgb(46, 221, 167); fill-opacity:0.7; pointer-events:all; } .area { fill:rgb(46, 221, 167); fill-opacity:0.4; pointer-events:all; } .desk:hover { fill:rgb(29, 255, 0); fill-opacity:0.6; pointer-events:all; } .desk { fill:rgb(29, 255, 0); fill-opacity:0.4; pointer-events:all; } .redbooks:hover { fill:rgb(255, 0, 0); fill-opacity:0.7; pointer-events:all; } .redbooks { fill:rgb(255, 0, 0); fill-opacity:0.4; pointer-events:all; } .books:hover { fill:rgb(150, 40, 177); fill-opacity:0.7; pointer-events:all; } .books { fill:rgb(150, 40, 177); fill-opacity:0.4; pointer-events:all; } #_x32_1-22_open_university:hover { fill:rgb(235, 255, 0); fill-opacity:0.7; pointer-events:all; } #_x32_1-22_open_university { fill:rgb(235, 255, 0); fill-opacity:0.4; pointer-events:all; } #_x32_1-_reading_literature:hover { fill:rgb(34, 213, 194); fill-opacity:0.7; pointer-events:all; } #_x32_1-_reading_literature { fill:rgb(34, 213, 194); fill-opacity:0.4; pointer-events:all; } #_x32_0_-_textbooks:hover { fill:rgb(128, 128, 128); fill-opacity:0.7; pointer-events:all; } #_x32_0_-_textbooks { fill:rgb(128, 128, 128); fill-opacity:0.4; pointer-events:all; } .services:hover { fill:rgb(110, 121, 246); fill-opacity:0.7; pointer-events:all; } .services { fill:rgb(110, 121, 246); fill-opacity:0.4; pointer-events:all; } .door:hover { fill:rgb(84, 144, 189); fill-opacity:0.7; pointer-events:all; } .door { fill:rgb(84, 144, 189); fill-opacity:0.4; pointer-events:all; } /*Tooltip styles*/ .tooltip { font-weight:700; font-size:22pt; } </style> </head> <body> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="612px" height="792px" viewBox="0 0 612 792" enable-background="new 0 0 612 792" xml:space="preserve"> <g id="map">...</g> <g id="Borders"> <polygon class="area" id="Silent_Room" fill="none" stroke="#000000" stroke-miterlimit="10" points="165.667,100.836 181.015,91.659 190.333,83.67 283.455,108.836 283.455,196.781 269.167,203.003 269.167,223.17 143.5,223.17 143.333,106.17 151.833,105.003"> <title>חדר שקט</title> </polygon> <polygon class="copier" id="Copier1" fill="none" stroke="#000000" stroke-miterlimit="10" points="226.667,239.668 226.667,226.668 202,226.668 202,239.333"> <title>מדפסות 1 ו-2</title> </polygon> <polygon class="copier" id="Copier_2" fill="none" stroke="#000000" stroke-miterlimit="10" points="252.167,226.668 228.167,226.668 227.833,239.668 252.167,239.333"> <title>מכונת צילום</title> </polygon> <polyline class="books" id="_x32_1-22_open_university" fill="none" stroke="#000000" stroke-miterlimit="10" points="192.842,261.333 192.842,264.833 248.917,264.833 248.917,268.333 276.583,268.333 276.583,261.333 192.083,261.167"> <title>21-22: אוסף האוניברסיטה הפתוחה</title> </polyline> <rect class="books" id="_x32_1-_reading_literature" x="192.083" y="265.167" fill="none" stroke="#000000" stroke-miterlimit="10" width="56.833" height="2.833"> <title>21: ספרות יפה</title> </rect> <polygon class="books" id="_x32_0_-_textbooks" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.667,283.5 262.5,283.5 263.167,287.167 277,287.167 277,279.833 192.592,279.585 191.667,279.833"> <title>19-20: Textbooks</title> </polygon> <polygon class="books" id="_x31_9_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="262.5,287.167 262.5,283.5 191.667,283.5 192.592,287.167"> <title>19: 681.31.06 מיצ'-סוף</title> </polygon> <polygon class="books" id="_x31_8_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,301.496 277,297.83 191.667,297.83 192.129,301.496 " > <title>18: 658.626-681.31.06 מדע</title> </polygon> <polygon class="books" id="_x31_7_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,305.163 277,301.497 191.667,301.497 192.129,305.163 " > <title>17: 658:577.4-658.58</title> </polygon> <polygon class="books" id="_x31_6_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,319.667 277,316 191.667,316 192.129,319.667 " > <title>16: 65.012.4-658</title> </polygon> <polygon class="books" id="_x31_5_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,324 277,320.333 191.667,320.333 192.129,324 " > <title>15: 65.01 Cap-65.012.32</title> </polygon> <polygon class="books" id="_x31_4_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,338.167 277,334.5 191.667,334.5 192.129,338.167 " > <title>14: 63.001.5-65.01 Bro</title> </polygon> <polygon class="books" id="_x31_3_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,341.833 277,338.167 191.667,338.167 192.129,341.833 " > <title>13: 621.382 Dan-63(9)(091)</title> </polygon> <polygon class="books" id="_x31_2_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,356.667 277,353 191.667,353 192.129,356.667 " > <title>12: 62-621.382 Cro</title> </polygon> <polygon class="books" id="_x31_1_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="277,360.333 277,356.667 191.667,356.667 192.129,360.333 " > <title>11: 591-618</title> </polygon> <polygon class="desk" id="Computer_Desk_1" fill="none" stroke="#000000" stroke-miterlimit="10" points="166.167,257.663 166.167,238.329 144.667,237.829 144.667,257.663 " > <title>שולחן מחשב</title> </polygon> <polygon class="desk" id="Computer_Desk_2" fill="none" stroke="#000000" stroke-miterlimit="10" points="166.167,297.083 166.167,277.75 144.667,277.25 144.667,297.083 " > <title>שולחן מחשב</title> </polygon> <polygon class="desk" id="Computer_Desk_3" fill="none" stroke="#000000" stroke-miterlimit="10" points="166.167,336.333 166.167,317 144.667,316.5 144.667,336.333 " > <title>שולחן מחשב</title> </polygon> <polygon class="desk" id="Computer_Desk_4" fill="none" stroke="#000000" stroke-miterlimit="10" points="166.167,376.5 166.167,357.167 144.667,356.667 144.667,376.5 " > <title>שולחן מחשב</title> </polygon> <polygon class="desk" id="Computer_Desk_5" fill="none" stroke="#000000" stroke-miterlimit="10" points="166.167,415.834 166.167,396.5 144.667,396 144.667,415.834 " > <title>שולחן מחשב</title> </polygon> <polygon class="books" id="_x31_0_-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,473.811 276.667,473.311 276.667,476.977 191.833,477.977 " > <title>10: 517 גוב-539.2</title> </polygon> <polygon class="books" id="_x39__-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,477.477 276.667,476.977 276.667,480.643 191.833,481.643 " > <title>9: 37.018.43-517 איי</title> </polygon> <polygon class="books" id="_x38__-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,491.978 276.667,491.478 276.667,495.144 191.833,496.144 " > <title>8: 338.982-37.018.26</title> </polygon> <polygon class="books" id="_x37__-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,495.644 276.667,495.144 276.667,498.81 191.833,499.81 " > <title>7: 333.013(73)-338.982</title> </polygon> <polygon class="books" id="_x36__-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,510.686 276.667,510.186 276.667,513.852 191.833,514.852 " > <title>6: 327-333(100)</title> </polygon> <polygon class="books" id="_x35__-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,513.269 276.667,512.769 276.667,516.435 191.833,517.435 " > <title>5: 301.16-326.1</title> </polygon> <polygon class="books" id="_x34__-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,529.046 276.667,528.546 276.667,532.212 191.833,533.212 " > <title>4: 159.953-301.154.12</title> </polygon> <polygon class="books" id="_x33__-_collection" fill="none" stroke="#000000" stroke-miterlimit="10" points="191.833,532.962 276.667,532.462 276.667,536.128 191.833,537.128 " > <title>3: 001.4-159.95</title> </polygon> <rect class="books" id="_x32__-_collection" x="191.833" y="547.48" fill="none" stroke="#000000" stroke-miterlimit="10" width="56.5" height="3.167" > <title>2: פרויקטים - הנדסאים</title> </rect> <rect class="books" id="_x31__-_collection" x="191.833" y="551.333" fill="none" stroke="#000000" stroke-miterlimit="10" width="56.5" height="3.167" > <title>1: 7(091)-796.4, קופסאות קיבוץ</title> </rect> <rect class="desk" id="Accessibility_Computer" x="319.25" y="509.125" fill="none" stroke="#000000" stroke-miterlimit="10" width="11.75" height="10.5" > <title>מחשב נגישות</title> </rect> <rect class="desk" id="Clinical_Psycology" x="319.25" y="496.977" fill="none" stroke="#000000" stroke-miterlimit="10" width="11.75" height="10.5" > <title>מחשב פסיכולוגיה קלינית</title> </rect> <rect class="services" id="Yaatz" x="319.25" y="468.612" fill="none" stroke="#000000" stroke-miterlimit="10" width="21.333" height="19.833" > <title>עמדת יעץ</title> </rect> <polygon class="services" id="Hashala" fill="none" stroke="#000000" stroke-miterlimit="10" points="429.666,469.945 384.666,469.945 384.416,456.112 430.082,456.112 " > <title>דלפק השאלה</title> </polygon> <rect class="redbooks" id="_x33_2_-_red" x="416.416" y="514.684" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>32: 001.81-35(9) שמורים</title> </rect> <rect class="redbooks" id="_x33_1_-_red" x="416.416" y="519.017" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>31: 352-65.012.2 שמורים</title> </rect> <rect class="redbooks" id="_x33_0-red_x2F_Seminars" x="416.416" y="534.601" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>30: 65.012.3-940.2 שמורים, עבודות סמינריוניות</title> </rect> <rect class="redbooks" id="_x32_9_-_syllabuses" x="416.416" y="538.684" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>29: מקראות</title> </rect> <rect class="redbooks" id="_x32_8_-_Jounala_articles_Ethiopia" x="416.416" y="554.517" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>28: עיתונות עליית יהודי אתיופיה</title> </rect> <rect class="redbooks" id="_x32_7_-_syllabuses" x="416.416" y="558.434" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>27: מקראות</title> </rect> <rect class="redbooks" id="_x32_6_-_dictionaries" x="416.416" y="574.414" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>26: R621.7(02)-R933.44 יעץ</title> </rect> <rect class="redbooks" id="_x32_5_-_dictionaries" x="416.416" y="578.831" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>25: R3(05)(9)-R621.7 יעץ</title> </rect> <rect class="redbooks" id="_x32_4_-_dictionaries" x="416.416" y="594.101" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>24: R03=20-R221(048) יעץ</title> </rect> <rect class="redbooks" id="_x32_3_-_dictionaries" x="416.416" y="598.518" fill="none" stroke="#000000" stroke-miterlimit="10" width="41.75" height="4.416" > <title>23: R000.81-R03:933.44 יעץ</title> </rect> <polygon class="area" id="Stairs_Down" fill="none" stroke="#000000" stroke-miterlimit="10" points="444.667,366.5 444.667,235.833 419.667,235.667 419.667,366.5 " > <title>מדרגות לקומת קרקע</title> </polygon> <polyline class="area" id="Staff_Offices" fill="none" stroke="#000000" stroke-miterlimit="10" points="314.168,523.434 314.168,698.499 414.5,698.499 414.5,496.144 362.835,496.144 362.835,521.226 314.168,521.226 " > <title>משרדים</title> </polyline> <polyline class="desk" id="Guard_Post" fill="none" stroke="#000000" stroke-miterlimit="10" points="444.667,196.781 425,196.781 425,220 444.667,220 444.667,195.5 " > <title>עמדת שומר</title> </polyline> <polyline class="door" id="Main_Entrance" fill="none" stroke="#000000" stroke-miterlimit="10" points="448.25,192.5 448.25,195.5 479.25,195.5 479.25,192.5 446.751,192.5 " > <title>דלת כניסה</title> </polyline> <polyline class="door" id="Emergency_Exit" fill="none" stroke="#000000" stroke-miterlimit="10" points="283,161.67 283,164.67 314,164.67 314,161.67 281.501,161.67 " > <title>יציאת חירום</title> </polyline> <polyline class="door" id="Emergency_Exit_1_" fill="none" stroke="#000000" stroke-miterlimit="10" points="278.166,559.143 278.166,562.143 309.166,562.143 309.166,559.143 276.667,559.143 " > <title>יציאת חירום</title> </polyline> <polygon class="redbooks" id="Staff_Publications" fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" points="419.667,405.917 415.5,405.848 415.5,376.5 419.667,376.362 " > <title>פרסומי סגל</title> </polygon> <rect class="desk" id="comp_x5F_station_x5F_2" x="277" y="277.25" fill="none" stroke="#000000" stroke-miterlimit="10" width="8.685" height="9.917" > <title>עמדת מחשב</title> </rect> <rect class="desk" id="comp_x5F_station_x5F_1" x="277" y="351.708" fill="none" stroke="#000000" stroke-miterlimit="10" width="8.685" height="9.917"> <title>עמדת מחשב</title> </rect> <rect class="desk" id="comp_x5F_station_x5F_3" x="498" y="215.042" fill="none" stroke="#000000" stroke-miterlimit="10" width="8.685" height="9.917"> <title>עמדת מחשב</title> </rect> <rect class="desk" id="comp_x5F_station_x5F_4" x="498" y="199.583" fill="none" stroke="#000000" stroke-miterlimit="10" width="8.685" height="9.917"> <title>עמדת מחשב</title> </rect> <polygon class="desk" id="comp_x5F_desk_x5F_win" fill="none" stroke="#000000" stroke-miterlimit="10" points="395.5,423.499 395.5,413.5 361.5,412.5 361.5,423.5 " > <title>עמדת מחשב</title> </polygon> <text transform="matrix(0.0047 0.8645 -1 0.0054 90.5835 351.708)" font-family="'MyriadPro-Regular'" font-size="33.8333">אולם קריאה</text> <text transform="matrix(-0.0012 0.8645 -1 -0.0014 519.0498 493.9395)" font-family="'MyriadPro-Regular'" font-size="33.8333">אולם השאלה</text> </g> </svg> </body> </html>