如何将样式定义添加到内联 svg?

How to add style definitions to inline svg?

我在 HTML 页面中有一个空的内联 SVG,并使用 Snap.SVG 填充和操作 SVG。我想对 SVG 元素使用 CSS 样式。

如何向 SVG(内联样式表)添加 style 部分?

你试过吗...

element.attr({ style: 'fill: green' });

举个例子?

样式表示例...

var frag = Snap.parse('<defs><style type="text/css"><![CDATA[ rect { stroke: #909; stroke-width: 10; fill: blue; } ]]></style>')
s.append( frag )

jsfiddle