Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
offset (using transform) svg element relative to its own size

I want to offset SVG element relative to its own size using translate with percentage, very similarly to how offset div using transform: translate(100%,0) would work:

this code:

  <div style={{ overflow: 'visible', position: 'relative' }}>
    {/* rect */}
    <div style={{ height: 20, width: 20, background: 'black', position: 'absolute' }} />
    {/* circle */}
    <div
      style={{
        height: 20,
        width: 20,
        background: 'purple',
        borderRadius: '50%',
        position: 'absolute',
        transform: 'translate(100%,0)',
      }}
    />
  </div>

will look like this enter image description here good, the circle offset was relative to its own size

while this case:

<svg overflow={'visible'}>
  <rect width={20} height={20} />
  <circle cx={10} cy={10} r="10" fill="purple" style={{ transform: 'translate(100%,0px)' }} />
</svg>

will cause this to render: enter image description here

It's basically being offset relative to the size of the svg canvas(that I never explicitly set): enter image description here

why does transform: 'translate(100%,0)' work relative to self in div html elements but relative to parent on SVG elements?

already tried:

  • wrapping g elements, or svg elements similar to other answers on this site.

want to avoid:

  • I could potentialy solve this by using .getbBox() function and calculate dimensions manually and save it to state and then offset by pixels, but I really want to avoid it and am looking for a simpler solution.

Demo

https://codesandbox.io/s/svg-vs-div-transform-translate-o2ii7

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should set the transform-box to fill-box. For React you use camel case so it looks like this:

style={{ transform: "translate(100%,0px)", transformBox: "fill-box" }}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!