Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

html - 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...