Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
How can I center the text element inside <g> element?

This is the structure of my SVG

<g id="CDT-B6-2">
   <path id="CDT-B6-box"/>
   <text x="1210" y="993" id="CDT-B6-text">888</text>
</g>

Problems:

  1. The textContent from text element is dynamic, it may shorter than length of 3
  2. Inside my SVG I have many <g id="CDT-B6-2"> but different ids & position
  3. I used x="50%" y="50%" to all text elements but it didn't put the text alignment centered from <g> element
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use dominant-baseline: middle and text-anchor: middle:

text {
  dominant-baseline: middle;
  text-anchor: middle;
}

rect {
  stroke: black;
  stroke-width: 2;
  fill: none;
}
<svg width="200" height="100">
  <g transform="translate(10 20)">
    <rect x="0" y="0" width="80" height="40" />
    <text x="40" y="20">888</text>
  </g>
  <g transform="translate(110 40)">
    <rect x="0" y="0" width="80" height="40" />
    <text x="40" y="20">888888</text>
  </g>
</svg>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda