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

290
Views
Resizing an SVG to fill a div

I have a div with an SVG inside of itmy map

The div is outlines by the blue dots and the SVG by the green. My SVG code inside of my HTML file:

<svg class="svg" height="500px" width="50%">
  <g class="chart" transform="translate(0,0)">
    <g class="state-g"> (Map here) </g>
  </g>
</svg>

My relevant CSS:

body, html {
  height: 100%;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}

.container {
  position: relative;
  align-content: center;
  padding-left: 10%;
  padding-right: 10%;
}

.svg {
  outline: 5px dotted blue;
  font: inherit;
  display: block;
  margin: auto;
}

svg g.chart {
  outline: 5px dotted green;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want your SVG to automatically scale to fill its container then it needs to have a viewBox attribute.

<svg class="svg" viewBox="...something...">
  <g class="chart" transform="translate(0,0)">
    <g class="state-g"> (Map here) </g>
  </g>
</svg>

The correct values for that viewBox will depend on the bounds of the content of that SVG. Check your original map file:

  • If it had a viewBox, then use that.
  • If it didn't have a viewBox, but it had hardwired width and height, then use those. For instance, if it had width="200px" height="350px", then replace those values with viewBox="0 0 200 350".
  • If it had neither. Then you will need to work out the correct viewBox values. There are several ways to do that. Check other questions on StackOverflow for some solutions. Or post a link to your SVG and we can tell you what it should be.
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!