在html下的svg下奇怪的空间

时间:2017-04-10 06:59:42

标签: html css svg

我在achor中有svg图像:



<a href="/firm-profilepl/homepl/indexpl" style="
    padding: 0;
    margin: 0;
    overflow: hidden;
    background: red;
    display: block;
    height: 100%;
">
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" style="background: #FFF"><path d="M497.913,497.913c-18.782,18.782-49.225,18.782-68.008,0l-84.862-84.863c-34.889,22.382-76.13,35.717-120.659,35.717  C100.469,448.767,0,348.312,0,224.383S100.469,0,224.384,0c123.931,0,224.384,100.452,224.384,224.383  c0,44.514-13.352,85.771-35.718,120.676l84.863,84.863C516.695,448.704,516.695,479.131,497.913,497.913z M224.384,64.109  c-88.511,0-160.274,71.747-160.274,160.273c0,88.526,71.764,160.274,160.274,160.274c88.525,0,160.273-71.748,160.273-160.274  C384.657,135.856,312.909,64.109,224.384,64.109z"/></svg>
</a>
&#13;
&#13;
&#13;

在svg下添加了一些额外的空间: http://i.imgur.com/vaVwcH8.png

如何摆脱它?

2 个答案:

答案 0 :(得分:0)

默认情况下,每个html元素都需要一些garbase css,要删除它只需在SVG标记中使用'display:block'。

<a href="/firm-profilepl/homepl/indexpl" style="
    padding: 0;
    margin: 0;
    overflow: hidden;
    background: red;
    display: block;
    height: 100%;
">
  <svg style="display:block" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" style="background: #FFF"><path d="M497.913,497.913c-18.782,18.782-49.225,18.782-68.008,0l-84.862-84.863c-34.889,22.382-76.13,35.717-120.659,35.717  C100.469,448.767,0,348.312,0,224.383S100.469,0,224.384,0c123.931,0,224.384,100.452,224.384,224.383  c0,44.514-13.352,85.771-35.718,120.676l84.863,84.863C516.695,448.704,516.695,479.131,497.913,497.913z M224.384,64.109  c-88.511,0-160.274,71.747-160.274,160.273c0,88.526,71.764,160.274,160.274,160.274c88.525,0,160.273-71.748,160.273-160.274  C384.657,135.856,312.909,64.109,224.384,64.109z"/></svg>
</a>

答案 1 :(得分:0)

您可以访问此link,了解为什么img标记底部总是有空格。

在这种情况下,只需在您的style="display:block;overflow:hidden;background:white"代码中添加svg属性。

<a href="/firm-profilepl/homepl/indexpl" style="
    padding: 0;
    margin: 0;
    overflow: hidden;
    background: red;
    display: block;
    height: 100%;
">
  <svg style="display:block;overflow:hidden;background:white" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 512 512" height="512px" id="Layer_1" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" style="background: #FFF"><path d="M497.913,497.913c-18.782,18.782-49.225,18.782-68.008,0l-84.862-84.863c-34.889,22.382-76.13,35.717-120.659,35.717  C100.469,448.767,0,348.312,0,224.383S100.469,0,224.384,0c123.931,0,224.384,100.452,224.384,224.383  c0,44.514-13.352,85.771-35.718,120.676l84.863,84.863C516.695,448.704,516.695,479.131,497.913,497.913z M224.384,64.109  c-88.511,0-160.274,71.747-160.274,160.273c0,88.526,71.764,160.274,160.274,160.274c88.525,0,160.273-71.748,160.273-160.274  C384.657,135.856,312.909,64.109,224.384,64.109z"/></svg>
</a>