在SVG中定义颜色 [英] Define color in SVG

查看:113
本文介绍了在SVG中定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SVG文件中定义颜色?

How do I define a Color in a SVG file?

<?xml version="1.0"?>
<svg width="704" height="702" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <!-- define mycolor=red -->
    </defs> 

    <!-- use mycolor as fill -->
    <rect x="0" y="0" width="704" height="702" fill=mycolor/>
</svg>

推荐答案

您可以将样式表与svg一起使用,并且如果未指定,则fill属性也将从其父元素继承而来.更改代码后,颜色为红色.如果.myfill类未赋予该颜色,则它将从"G"组标记继承蓝色.

You can use a style sheet with svg and the fill property is also inhered from its parent element assuming you do not specify it. In this change to your code the color is red. If it were not given that color by the .myfill class it would be inherit blue from the "G" group tag.

<?xml version="1.0"?>
<svg width="704" height="702" xmlns="http://www.w3.org/2000/svg">

<style>
.myfill { fill:red }
</style>

    <g fill="blue">
    <rect x="0" y="0" width="704" height="702" class="myfill" />
    </g>

</svg>

这篇关于在SVG中定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆