I have the following code:
.container{
width: 100px;
height: 200px;
background-color: red;
resize: both; /* Just to make it... */
overflow: hidden; /* ...resizable for testing. */
}
<div class="container">
<svg width="100%" height="100%">
<circle cx="50%" cy="50%" r="25%" fill="black"></circle>
</svg>
</div>
As I resize .container
, I can easily see that:
cx
is percentage of the widthcy
is percentage of the height
But I cannot understand what r
is percentage of. What is r
percentage of?
2
Answers
cx (Center X):
cy (Center Y):
r (Radius):
Read the documentation
As commented by Roko C. Buljan when using % units the relative value refers to the normalized diagonal.
See the W3C SVG specs "8.9. Units"
here’s an example
You can also check your calculations using the
baseVal
property from theSVGAnimatedLength
interface.