【发布时间】:2014-10-03 14:20:52
【问题描述】:
我使用 Inkscape 创建 svg 图像,想知道如何使用非嵌入式 css 规则。
例如
- 绘制矩形
- 在 XML 编辑器中添加类属性为
class="rect1"
如何添加css之类的
.rect1 { 填充:#ffef00; }
【问题讨论】:
我使用 Inkscape 创建 svg 图像,想知道如何使用非嵌入式 css 规则。
例如
class="rect1"
如何添加css之类的
.rect1 { 填充:#ffef00; }
【问题讨论】:
以下是 HTML 页面中的 SVG 示例,您可以使用 CSS 设置样式:
HTML 页面
<div id="mySvg">
<svg>
<use xlink:href="images/logo.svg#shape" />
</svg>
</div>
SVG(位于 images/logo.svg)
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<g id="shape">
<rect x="50" y="50" width="50" height="50" />
<circle cx="50" cy="50" r="50" />
</g>
</defs>
</svg>
CSS
svg {
fill: currentColor;
}
#mySvg {
color: green;
}
查看工作示例:plunker
备注
fill 属性(fill 应该在 CSS 中)。使用 Inkscape 制作 SVG 时,它通常有一个 fill:none 或其他东西。您必须手动删除它们。【讨论】: