简体   繁体   English

Web 上 svg 图标周围的空白区域

[英]white space around svg icon on web

i use google material icon, and it has white space around it.我使用谷歌材料图标,它周围有空白。 When i apply sizing for the svg, it still keeps white space around it and the icon is tiny.当我为 svg 应用大小时,它仍然保留周围的空白,并且图标很小。 小 svg I add css to svg or a wrapper div it doesn't matter.我将 css 添加到 svg 或包装 div 没关系。

css css

svg {
    height: 16px;
    width: 16px;
}

html html

<svg>
   <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/assets/path.svg#ic_arrow_drop_down"></use>
</svg>

箭头下拉

the svg file contains svg 文件包含

<svg xmlns="http://www.w3.org/2000/svg" style="display:none;">
... more symbols...
    <symbol id="ic_arrow_drop_down" viewBox="0 0 24 24">
        <path d="M7 10l5 5 5-5z"/>
        <path d="M0 0h24v24H0z" fill="none"/>
    </symbol>
... more symbols...
</symbol>

I guess the viewBox is the wrong size.我猜viewBox的大小不正确。 Try viewBox="7 10 10 10" .试试viewBox="7 10 10 10"

 svg { width: 16px; height: 16px; }
 <svg id="ic_arrow_drop_down" viewBox="7 10 10 10 "> <path d="M7 10l5 5 5-5z" /> </svg>

I think the second path is obsolete, I have removed it.我认为第二条路径已过时,我已将其删除。

I had the same problem but with this code, I could fix it我有同样的问题,但使用此代码,我可以修复它

<svg class="icon icon-bookmark"><use xlink:href="#icon-bookmark"></use>
     <symbol id="icon-bookmark" viewBox="0 0 32 32">
          <path d="M6 0v32l10-10 10 10v-32z"></path>
     </symbol>
</svg>


.icon {
   display: inline-block;
   width: 8rem;
   height: 8rem;
   stroke-width: 0;
   stroke: currentColor;
   fill: currentColor;

} }

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

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