0

我从 VML 迁移到 SVG。路径填充方式有问题。这是一个例子:

用 VML 和 SVG 绘制的星星

左边是用 VML 绘制的星形,右边是用 SVG 绘制的。VML 的源代码(仅适用于 IE):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
    <style> v\:* { behavior: url(#default#VML); }</style >
</head>
<body>
    <div style="width:300; height:270;">
        <v:shape fillcolor="blue" strokecolor="red" coordorigin="0 0" coordsize="300 270"
            strokeweight="2" style="position:relative; top:20; left:20; width:300; height:270" 
            path="m150,20 l240,240 l30,90 l270,90 l60,240 x e">
        </v:shape>
    </div>
</body>

SVG的源代码:

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <svg width="300" height="270">
            <path d="M150,20 L240,240 L30,90 L270,90 L60,240 Z" fill="blue" stroke="red" stroke-width="3"/>
        </svg>
    </body>
</html>

星星中间填充有明显区别。我更喜欢 VML 风格。有没有办法用 SVG 做到这一点?

4

1 回答 1

3

当然,您只需要一个偶数填充规则

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <svg width="300" height="270">
            <path d="M150,20 L240,240 L30,90 L270,90 L60,240 Z" fill-rule="evenodd" fill="blue" stroke="red" stroke-width="3"/>
        </svg>
    </body>
</html>
于 2013-02-07T07:25:21.650 回答