nia daniels
nia daniels

Reputation: 15

How can I get rid of the space my SVG is taking up and why am I unable to change its size?

SVG extra space will not go away, when you inspect the SVG you cant see a big blue space pushing everything else down. I've had so many tabs over and tried so many things, such as height:auto; , display: block; , changing the view box and more.

I cannot change the size of SVG outside of the media query. I read that it's already inline but it definitely isn't acting like it considering all that space it's taking up.

 <svg version="1.1" style="display: block;" viewBox="0 0 800 800">
        <defs>
          <!-- The text path: see links above regarding coordinate system -->
          <path d="M0, 200a200, 200 0 1, 0 400, 0a200, 200 0 1, 0 -400, 0" id="txt-path"></path>
        </defs>

        <text fill="black" font-size="45.5" font-family="moholregular">
          <!-- This is the magic -->
          <textPath startOffset="0" xlink:href="#txt-path">Try our all new baby name generator</textPath>
        </text>
      </svg>

Link to the entire page via codepen

Upvotes: 1

Views: 119

Answers (1)

Paul LeBeau
Paul LeBeau

Reputation: 101820

Your problem is that your viewBox is not set to appropriate values. It is set to have 800 width and 800 height. But your content is nowhere near that big.

If we colour the background of the SVG we can see that.

svg {
  width: 400px;
  background-color: linen;
}
<svg version="1.1" style="display: block;" viewBox="0 0 800 800">
  <defs>
    <!-- The text path: see links above regarding coordinate system -->
    <path d="M0, 200a200, 200 0 1, 0 400, 0a200, 200 0 1, 0 -400, 0" id="txt-path"></path>
  </defs>

  <text fill="black" font-size="45.5" font-family="moholregular">
    <!-- This is the magic -->
    <textPath startOffset="0" xlink:href="#txt-path">Try our all new baby name generator</textPath>
  </text>
</svg>

The viewBox should be set to values that are tighter around the graphic.

For example: viewBox="-10 151 420 260".

svg {
  width: 400px;
  background-color: linen;
}
<svg version="1.1" style="display: block;" viewBox="-10 151 420 260">
  <defs>
    <!-- The text path: see links above regarding coordinate system -->
    <path d="M0, 200a200, 200 0 1, 0 400, 0a200, 200 0 1, 0 -400, 0" id="txt-path"></path>
  </defs>

  <text fill="black" font-size="45.5" font-family="moholregular">
    <!-- This is the magic -->
    <textPath startOffset="0" xlink:href="#txt-path">Try our all new baby name generator</textPath>
  </text>
</svg>

Upvotes: 1

Related Questions