简体   繁体   English

SVG 占用了额外的空间,并且边距不适用于文本元素

[英]SVG is taking up extra space and margin is not working on text element

I have the following SVG code:我有以下 SVG 代码:

<svg width="100%" height="100px">
  <text x="50%" y="60%" text-anchor="middle" style="">Name</text>
</svg>

This gives the following result.这给出了以下结果。 Too much extra space below the name.名称下方多余的空格。 No matter what I try I cannot reduce it.无论我尝试什么,我都无法减少它。 Setting custom height cuts the name from the top.设置自定义高度会从顶部剪切名称。

在此处输入图片说明

If I change the height the Name gets cut from the top and margin is not working on text element.如果我更改高度,名称会从顶部剪切,并且边距不适用于文本元素。

<svg width="100%" height="40px">
  <text x="50%" y="60%" text-anchor="middle" style="margin-top: 10px;">Name</text>
</svg>

在此处输入图片说明

What is the issue?问题是什么?

You may try the dy property of the text element.你可以试试 text 元素的 dy 属性。

<svg width="100%" height="100px" >
  <text x="50%" y="60%" text-anchor="middle" dy="10px">Name</text>
</svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM