我尝试使用内联样式标签来为我的45个多边形和5个矩形设置样式。但是不知何故,第一个尝试设置样式的标签没有生效。如果我在顶部添加第三个形状,则其下面的两个形状会被设置样式;如果我移除顶部的第三个形状,则其下方的第二个形状将无法被设置样式。有人遇到过这种情况吗?
<style type="text/css"><![CDATA[ <!--this rectangle will not be styled --> rect{ fill:none; stroke:black; stroke-width:.5; } polygon{ fill:none; stroke:black; stroke-width:.5; }]]></style>
现在使用以下代码,矩形将被设置样式。(第二个多边形标签位于顶部)
<style type="text/css"><![CDATA[
polygon{
fill:none;
stroke:black;
stroke-width:.5;
}
rect{
fill:none;
stroke:black;
stroke-width:.5;
}
polygon{
fill:none;
stroke:black;
stroke-width:.5;
}
]]></style>
<svg width="400" height="800" viewBox="0 0 400 800" id="svg-doc">
<rect id="central-park" class="shape" x="154" y="370"width="53" height="127" />
<rect id="shape-z10024" class="shape" x="68" y="415" width="85" height="40" />
<rect id="shape-z10023" class="shape" x="68" y="457" width="85" height="40" />
<polygon id="shape-z10034" class="shape" points="189,156 137,122 106,121 101,129 99,155 79,155 78,105 94,79 121,67 128,82 163,61 177,62 191,80" />
<a xlink:href="http://google.com/">
<polygon id="shape-z10040" class="shape" points="188,167 186,155 137,122 108,122 102,126 100,153 77,156 77,166" />
</a>
<polygon id="shape-z10033" class="shape" points="189,166 187,197 187,203 81,203 77,194 78,166" />
<polygon id="shape-z10032" class="shape" points="189,205 160,234 155,248 84,247 80,204" />
<polygon id="shape-z10030" class="shape" points="268,311 196,315 197,299 157,298 157,273 234,273" />
</svg>
<style>
标签中有一个XML注释?你的实际样式表中是否存在?另外,尝试用CSS注释(而不是XML注释)包装你的CDATA分隔符。还需要查看你的SVG标记。 - BoltClock