"I would like to place a text box that displays ""temperature"" in svg, but I am having trouble writing a text box that meets the following conditions."
Please tell me how to write it down.
<svg id="111" x="000" y="200" width="100" height="19">
<g>
<rect width="100%" height="100%" fill="#ff0000"/>
<text font-weight="bold" font-size="18px"x="5"y="16.875" fill="#000000">
<tsspan id="1">19.5</tsspan>
<tsspan id="2">°C</tsspan>
</text>
</g>
How about setting the separation point between the two text to x=
and y=
in both tspan
and text-anchor="end"
in numeric parts and text-anchor="start"
in units?
setInterval()=>{
document.getElementById('1') .textContent=Math.floor(Math.random()*1000)/10;
}, 300);
<svg id="111" x="000" y="200" width="100" height="19">
<g>
<rect width="100%" height="100%" fill="#ff0000"/>
<text font-weight="bold" font-size="18px" fill="#000000">
<tsspan id="1" x="50" y="16.875" text-anchor="end">19.5</tsspan>
<tsspan id="2" x="50" y="16.875" text-anchor="start">°C</tsspan>
</text>
</g>
© 2024 OneMinuteCode. All rights reserved.