How do I perfectly center a single character inside an SVG circle?

Seth Ladd

I'd like to place a single character, perfectly centered, inside this circle:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" width="100" height="100">
  <g>
    <circle style="fill:#eeeeee" cx="50" cy="50" r="50">
    </circle>
    <text>C</text>
  </g>
</svg>

Ideally, the solution works for any single ASCII character.

Thanks for the help!

r3mainer

Use a combination of text-anchor="middle" to centre the text horizontally, and dominant-baseline="central" to centre it vertically.

To simplify things, I've added a transform attribute to your <g> element to move the origin to the middle of your canvas.

<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
  <g transform="translate(50,50)">
    <circle style="fill:#eeeeee" r="50" />
    <text text-anchor="middle" dominant-baseline="central">C</text>
  </g>
</svg>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I make the circle around my "i" perfectly circular?

From Dev

How to center a circle in an svg

From Dev

Trying to center an svg circle inside a div

From Dev

How to perfectly center a "plus" sign in a circle using CSS

From Dev

How do I center an svg in my html?

From Dev

How can I place text inside an SVG circle with React JS?

From Dev

How do I center forms inside a table?

From Dev

How do I center the text inside the white?

From Dev

How do I get this circle get in the center of the box?

From Dev

How to set image on center of svg circle?

From Dev

How Do I Perfectly Center a Float Element in Between Two Floated Elements?

From Dev

How do I draw x number of circles around a central circle, starting at the top of the center circle?

From Dev

SVG center text in circle

From Dev

How do I add an image inside a rectangle or a circle in JavaFX?

From Dev

How do I restrict UIControlEventTouchUpInside for a circular UIButton to only inside the circle?

From Dev

How do I restrict UIControlEventTouchUpInside for a circular UIButton to only inside the circle?

From Dev

How do I plot random points inside a circle using OpenGL?

From Dev

How to add a link inside an svg circle

From Dev

How do distribute n points inside a circle according to given "relative probability" for each of having a certain distance from a circle center?

From Dev

How do distribute n points inside a circle according to given "relative probability" for each of having a certain distance from a circle center?

From Dev

How do I center a character in a box using CSS?

From Dev

How do I center a GridView inside a fragment with viewpager

From Dev

How do I center a UIImage inside a UITableView cell?

From Dev

How do I center the elements inside a div from the below code

From Dev

How do I center a UIImage inside a UITableView cell?

From Dev

How can I display an image inside SVG circle in html5?

From Dev

SVG image inside circle

From Dev

SVG path inside circle

From Dev

How to center text inside a SVG g element?

Related Related

  1. 1

    How do I make the circle around my "i" perfectly circular?

  2. 2

    How to center a circle in an svg

  3. 3

    Trying to center an svg circle inside a div

  4. 4

    How to perfectly center a "plus" sign in a circle using CSS

  5. 5

    How do I center an svg in my html?

  6. 6

    How can I place text inside an SVG circle with React JS?

  7. 7

    How do I center forms inside a table?

  8. 8

    How do I center the text inside the white?

  9. 9

    How do I get this circle get in the center of the box?

  10. 10

    How to set image on center of svg circle?

  11. 11

    How Do I Perfectly Center a Float Element in Between Two Floated Elements?

  12. 12

    How do I draw x number of circles around a central circle, starting at the top of the center circle?

  13. 13

    SVG center text in circle

  14. 14

    How do I add an image inside a rectangle or a circle in JavaFX?

  15. 15

    How do I restrict UIControlEventTouchUpInside for a circular UIButton to only inside the circle?

  16. 16

    How do I restrict UIControlEventTouchUpInside for a circular UIButton to only inside the circle?

  17. 17

    How do I plot random points inside a circle using OpenGL?

  18. 18

    How to add a link inside an svg circle

  19. 19

    How do distribute n points inside a circle according to given "relative probability" for each of having a certain distance from a circle center?

  20. 20

    How do distribute n points inside a circle according to given "relative probability" for each of having a certain distance from a circle center?

  21. 21

    How do I center a character in a box using CSS?

  22. 22

    How do I center a GridView inside a fragment with viewpager

  23. 23

    How do I center a UIImage inside a UITableView cell?

  24. 24

    How do I center the elements inside a div from the below code

  25. 25

    How do I center a UIImage inside a UITableView cell?

  26. 26

    How can I display an image inside SVG circle in html5?

  27. 27

    SVG image inside circle

  28. 28

    SVG path inside circle

  29. 29

    How to center text inside a SVG g element?

HotTag

Archive