简体   繁体   English

SVG 多边形填充 svg 父

[英]SVG polygon to fill svg parent

I have an svg polygon and I am trying to get the polygon to fill to the size of the svg container.我有一个 svg 多边形,我试图让多边形填充到 svg 容器的大小。 Changing the height and width attributes scales the polygon as expected however I do not want any of the whitespace between the polygon and svg.更改高度和宽度属性会按预期缩放多边形,但是我不想要多边形和 svg 之间的任何空白。 Is there a way to achieve this without having to re-do the points?有没有办法实现这一点而不必重新做点?

<?xml version="1.0" encoding="UTF-8"?>
<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <title>2</title>
    <g id="2" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <polygon id="Rectangle" fill="#000000" points="6 4 14 4 14 12.6416575 10 16 6 12.6416575"></polygon>
    </g>
</svg>

You could adjust the viewBox instead eg您可以改为调整 viewBox,例如

 <svg width="20px" height="20px" viewBox="6 4 8 12" preserveAspectRatio="none" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="background-color:red"> <title>2</title> <g id="2" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <polygon id="Rectangle" fill="#000000" points="6 4 14 4 14 12.6416575 10 16 6 12.6416575"></polygon> </g> </svg>

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

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