class
将一个类名称或一组类名称分配给一个元素。您可以将相同的类名称或名称分配给任意数量的元素,但多个类名称必须用空格字符分隔。
一个元素的类名有两个关键的作用:
- 作为样式表选择器,用于当作者将样式信息分配给一组元素时。
- 浏览器的一般用途。
您可以通过此类来使用CSS设置SVG内容的样式。
用法上下文
分类 | 没有 |
---|---|
值 | <列表的级-名> |
动画 | 是 |
规范性文件 | SVG 1.1(第二版):类属性 |
List-of-Ts
<list-of-Ts>
(其中T是某种类型)列表由一个分离的值序列组成。除非另有明确说明,否则SVG XML属性中的列表可以用逗号分隔(逗号前后可添加可选空格),或用空格分隔。
列表中的空格可定义为下列连续字符中的一个或多个:
“空格”(U + 0020),“制表”(U + 0009),“换行”(U + 000A),“回车”(U + 000D)和“换页”(U + 000C)。
以下是描述<list-of-Ts>语法的EBNF语法的模板:
list-of-Ts ::= T
| T, list-of-Ts
在SVG DOM中,一个<list-of-Ts>类型的值由特定类型T的特定接口表示。例如,一个<list-of-lengths>在SVG DOM中用一个SVGLengthList
或一个SVGAnimatedLengthList
对象表示。
实例
<html>
<body>
<svg width="120" height="220"
viewPort="0 0 120 120" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<style type="text/css" >
<![CDATA[
rect.rectClass {
stroke: #000066;
fill: #00cc00;
}
circle.circleClass {
stroke: #006600;
fill: #cc0000;
}
]]>
</style>
<rect class="rectClass" x="10" y="10" width="100" height="100"/>
<circle class="circleClass" cx="40" cy="50" r="26"/>
</svg>
</body>
</html>
适用元素
以下元素可以使用该class
属性:
<a>
<altGlyph>
<circle>
<clipPath>
<defs>
<desc>
<ellipse>
<feBlend>
<feColorMatrix>
<feComponentTransfer>
<feComposite>
<feConvolveMatrix>
<feDiffuseLighting>
<feDisplacementMap>
<feFlood>
<feGaussianBlur>
<feImage>
<feMerge>
<feMorphology>
<feOffset>
<feSpecularLighting>
<feTile>
<feTurbulence>
<filter>
<font>
<foreignObject>
<g>
<glyph>
<glyphRef>
<image>
<line>
<linearGradient>
<marker>
<mask>
<missing-glyph>
<path>
<pattern>
<polygon>
<polyline>
<radialGradient>
<rect>
<stop>
<svg>
<switch>
<symbol>
<text>
<textPath>
<title>
<tref>
<tspan>
<use>
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | ? | ? | ? |
Animation support | ? | 5 (5) | ? | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com