SVG は文書の多くのパラメタを記述する スタイル付けプロパティ を利用する。スタイル付けプロパティは SVG 内容のグラフィックス要素がどのように描画されるかを定義する。 SVG におけるスタイル付けプロパティは次に挙げるものに利用される:
SVG uses styling properties to describe many of its document parameters. Styling properties define how the graphics elements in the SVG content are to be rendered. SVG uses styling properties for the following:
SVG はその多くのスタイル付けプロパティを CSS [CSS2] および XSL [XSL] と共有する。 SVG 固有の規則がこの仕様で明示されている場合を除き、 CSS および XSL と共有するプロパティの正式な定義は CSS2 仕様 [CSS2] で与えられる。
SVG shares many of its styling properties with CSS [ CSS2 ] and XSL [ XSL ]. Except for any additional SVG-specific rules explicitly mentioned in this specification, the normative definition of properties that are shared with CSS and XSL is the definition of the property from the CSS2 specification [ CSS2 ].
次に挙げるプロパティが CSS と SVG で共有される。これらのほとんどは XSL でも定義されている:
The following properties are shared between CSS2 and SVG. Most of these properties are also defined in XSL:
以下の SVG プロパティは [CSS2] で定義されていない。これらの完全かつ正式な定義はこの仕様に含まれている:
The following SVG properties are not defined in [ CSS2 ]. The complete normative definitions for these properties are found in this specification:
スタイル付けプロパティの要約された一覧は プロパティ索引 を見よ。
A table that lists and summarizes the styling properties can be found in the Property Index .
スタイル付けにはそれぞれ異なった目的を果たすための様々な利用がある。よくある3つの筋書きを挙げる:
SVG has many usage scenarios, each with different needs. Here are three common usage scenarios:
SVG 内容が(スタイルシート言語に依存しない)交換用の形式として利用される:
SVG content used as an exchange format (style sheet language-independent):
ソフトウエアツール間で SVG 内容が確実に共用できることが主要な目的になる場合がある。全ての実装で特定のスタイルシート言語がサポートされていることは保証されないので、 SVG 内容がスタイルシート言語抜きで指定できることが要求される。
In some usage scenarios, reliable interoperability of SVG content across software tools is the main goal. Since support for a particular style sheet language is not guaranteed across all implementations, it is a requirement that SVG content can be fully specified without the use of a style sheet language.
XSLT [XSLT] から出力される SVG 内容:
SVG content generated as the output from XSLT [ XSLT ]:
XSLT は任意の XML 内容をストリーム入力として、複雑な変換を適用し、 SVG 内容を出力として生成する能力を提供する。 XSLT を利用すればデータベースから抽出された XML データをグラフィック表現に変換することができる。 XSLT から完全な SVG 内容が生成できることが要求される。
XSLT offers the ability to take a stream of arbitrary XML content as input, apply potentially complex transformations, and then generate SVG content as output. XSLT can be used to transform XML data extracted from databases into an SVG graphical representation of that data. It is a requirement that fully specified SVG content can be generated from XSLT.
[CSS2] によってスタイル付けされた SVG 内容 :
SVG content styled with CSS [ CSS2 ]:
CSS はスタイル付けプロパティを XML 内容( SVG 内容も含まれる)にあてがうための宣言的言語であり、広く一般に実装されている。 CSS は特色機能の組み合わせ, 単純性, 経済性を表現し、 SVG の多くの応用に非常に適したものである。 CSS によるスタイル付けが SVG 内容に適用できることが要求される。
CSS is a widely implemented declarative language for assigning styling properties to XML content, including SVG. It represents a combination of features, simplicity and compactness that makes it very suitable for many applications of SVG. It is a requirement that CSS styling can be applied to SVG content.
以下の2つの方法でスタイル付けプロパティを SVG 要素にあてがうことができる:
Styling properties can be assigned to SVG elements in the following two ways:
プレゼンテーション属性
Presentation attributes
スタイル付けプロパティは SVG の プレゼンテーション属性 ( presentation attributes )であてがうことができる。この仕様で定義されている各スタイル付けプロパティに対し、対応する XML プレゼンテーション属性があり、関連する全ての SVG 要素で利用できる。プレゼンテーション属性についての詳細は プレゼンテーション属性を用いてプロパティを指定する でとりあげる。
Styling properties can be assigned using SVG's presentation attributes . For each styling property defined in this specification, there is a corresponding XML presentation attribute available on all relevant SVG elements. Detailed information on the presentation attributes can be found in Specifying properties using the presentation attributes .
プレゼンテーション属性はスタイルシート言語とは独立なので、上記筋書き1(即ちツール間での共用)が適用できる。 XSLT から XML 属性に値を与えることは素直にできることなので、プレゼンテーション属性は上記筋書き2(即ち XSLT から SVG を生成すること)にうってつけである。(下の XSL によるスタイル付け を見よ)
The presentation attributes are style sheet language independent and thus are applicable to usage scenario 1 above (i.e., tool interoperability). Because it is straightforward to assign values to XML attributes from XSLT, the presentation attributes are well-suited to usage scenario 2 above (i.e., SVG generation from XSLT). (See Styling with XSL below.)
適合 SVG インタープリタ と 適合 SVG ビューア には SVG のプレゼンテーション属性のサポートが要求される。
Conforming SVG Interpreters and Conforming SVG Viewers are required to support SVG's presentation attributes.
CSS
CSS
上記筋書き3をサポートするには SVG 内容が CSS によってスタイル付けできなければならない。詳細は CSS によるスタイル付け を見よ。
To support usage scenario 3 above, SVG content can be styled with CSS. For more information, see Styling with CSS .
素の(即ちテキストベースの) XML 内容に対する CSS によるスタイル付けをサポートする 適合 SVG インタープリタ と 適合 SVG ビューア には SVG 内容に対する CSS によるスタイル付けのサポートが要求される。
Conforming SVG Interpreters and Conforming SVG Viewers that support CSS styling of generic (i.e., text-based) XML content are required to support CSS styling of SVG content.
この仕様で定義される各スタイル付けプロパティ( プロパティ索引 を見よ)に対し、対応する同じ名前の XML 属性( プレゼンテーション属性 )が存在し、関連する全ての SVG 要素で利用できる。例えば SVG には図形の内部をどのように塗るかを定義する 'fill' プロパティがある。対応する同じ名前のプレゼンテーション属性(即ち fill )を与えられた要素の 'fill' プロパティの値の指定に利用できる。
For each styling property defined in this specification (see Property Index ), there is a corresponding XML attribute (the presentation attribute ) with the same name that is available on all relevant SVG elements. For example, SVG has a 'fill' property that defines how to paint the interior of a shape. There is a corresponding presentation attribute with the same name (i.e., fill ) that can be used to specify a value for the 'fill' property on a given element.
次の例にプレゼンテーション属性 fill, stroke を用いて 'fill' および 'stroke' プロパティを矩形に指定する方法を示す。
The following example shows how the 'fill' and 'stroke' properties can be assigned to a rectangle using the fill and stroke presentation attributes. The rectangle will be filled with red and outlined with blue:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="10cm" height="5cm" viewBox="0 0 1000 500" xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect x="200" y="100" width="600" height="300" fill="red" stroke="blue" stroke-width="3"/> </svg>
プレゼンテーション属性には次に挙げる利点がある:
The presentation attributes offer the following advantages:
プレゼンテーション属性を利用する SVG 内容は、 CSS のようなスタイルシート言語でスタイル付けされた SVG 内容( CSS によるスタイル付け を見よ)と比較して潜在的限界を持つことがある。場合によっては( XSLT スタイルシートによって意味内容に満ちた XML ソースファイルから SVG 内容が生成される様な場合など)下に述べる限界はあてはまらないかもしれない。以下に述べる潜在的限界がプレゼンテーション属性にあてはまるかどうかは状況に依存する。
In some situations, SVG content that uses the presentation attributes has potential limitations versus SVG content that is styled with a style sheet language such as CSS (see Styling with CSS ). In other situations, such as when an XSLT style sheet generates SVG content from semantically rich XML source files, the limitations below may not apply. Depending on the situation, some of the following potential limitations may or may not apply to the presentation attributes:
CSS をサポートするUAにおいては、プレゼンテーション属性は CSS2 仕様の 6.4.4 節( Precedence of non-CSS presentational hints )で述べられているようにして、対応するスタイル規則に変換され、文書作成者のスタイルシートに追加されなければならない。この追加においては、概念的には、プレゼンテーション属性は新しいスタイルシートに挿入され、それが文書作成者の一連のスタイルシートの最初のものになるとみなされる。すなわち CSS2 カスケード の過程においては、プレゼンテーション属性はあたかも対応する CSS スタイル規則に置き換えられ、文書作成者のスタイルシートの冒頭に固有性( specificity )を0として置かれたかのように働く。このことは、一般的にプレゼンテーション属性は文書作成者の他の CSS スタイル規則または style 属性より優先度が低いことを意味する。
For user agents that support CSS, the presentation attributes must be translated to corresponding CSS style rules according to rules described in section 6.4.4 of the CSS2 specification, Precedence of non-CSS presentational hints , with the additional clarification that the presentation attributes are conceptually inserted into a new author style sheet which is the first in the author style sheet collection. The presentation attributes thus will participate in the CSS2 cascade as if they were replaced by corresponding CSS style rules placed at the start of the author style sheet with a specificity of zero. In general, this means that the presentation attributes have lower priority than other CSS style rules specified in author style sheets or style attributes.
CSS をサポートしないUAでは、いかなる CSS スタイル規則も style 属性も無視しなければならない。この場合、 CSS2 カスケードは適用されない。(しかし、プロパティの継承は適用される。 プロパティ継承 を見よ。)
User agents that do not support CSS must ignore any CSS style rules defined in CSS style sheets and style attributes. In this case, the CSS cascade does not apply. (Inheritance of properties, however, does apply. See Property inheritance .)
プレゼンテーション属性定義内の !important 宣言はエラーである。
An !important declaration within a presentation attribute definition is an error.
プレゼンテーション属性のアニメーションは対応するプロパティのアニメーションと同値である。したがって attributeType="XML" のプレゼンテーション属性と対応する attributeType="CSS" のプロパティによるアニメーションの効果は同一である。
Animation of presentation attributes is equivalent to animating the corresponding property. Thus, the same effect occurs from animating the presentation attribute with attributeType="XML" as occurs with animating the corresponding property with attributeType="CSS" .
SVG のすべてのプレゼンテーション属性に対し以下の実体が DTD で定義される。
The following entities are defined in the DTD for all of the presentation attributes in SVG:
<!ENTITY % SVG.Core.attrib "" > <!ENTITY % SVG.Container.attrib "" > <!ENTITY % SVG.Conditional.attrib "" > <!ENTITY % SVG.Style.attrib "" > <!ENTITY % SVG.Viewport.attrib "" > <!ENTITY % SVG.Text.attrib "" > <!ENTITY % SVG.TextContent.attrib "" > <!ENTITY % SVG.Font.attrib "" > <!ENTITY % SVG.Paint.attrib "" > <!ENTITY % SVG.Color.attrib "" > <!ENTITY % SVG.Opacity.attrib "" > <!ENTITY % SVG.Graphics.attrib "" > <!ENTITY % SVG.Marker.attrib "" > <!ENTITY % SVG.Profile.attrib "" > <!ENTITY % SVG.Gradient.attrib "" > <!ENTITY % SVG.Clip.attrib "" > <!ENTITY % SVG.Mask.attrib "" > <!ENTITY % SVG.Filter.attrib "" > <!ENTITY % SVG.FilterColor.attrib "" > <!ENTITY % SVG.DocumentEvents.attrib "" > <!ENTITY % SVG.GraphicalEvents.attrib "" > <!ENTITY % SVG.Cursor.attrib "" > <!ENTITY % SVG.XLinkEmbed.attrib "" > <!ENTITY % SVG.External.attrib "" >
XSL スタイルシート( [XSLT] を見よ)は XML 内容をどのようなものに変換するか(通常は他の XML だが)を定義する。 XSLT が SVG に関連して利用される場合、 XSL スタイルシートの入力と出力が共に SVG 内容のときもあれば、 SVG 内容でない入力に対して SVG 内容を出力する場合もある。
XSL style sheets (see [ XSLT ]) define how to transform XML content into something else, usually other XML. When XSLT is used in conjunction with SVG, sometimes SVG content will serve as both input and output for XSL style sheets. Other times, XSL style sheets will take non-SVG content as input and generate SVG content as output.
外部 XSL スタイルシートを用いて SVG 内容を別の SVG 内容へ変換する例を示す( 外部スタイルシートへの参照 を見よ)。スタイルシートは全ての矩形に対し 'fill' プロパティを赤色に、 'stroke' プロパティを青色に設定する:
The following example uses an external XSL style sheet to transform SVG content into modified SVG content (see Referencing external style sheets ). The style sheet sets the 'fill' and 'stroke' properties on all rectangles to red and blue, respectively:
mystyle.xsl <?xml version="1.0" standalone="no"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg"> <xsl:output method="xml" encoding="utf-8" doctype-public="-//W3C//DTD SVG 1.1//EN" doctype-system="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"/> <!-- 最上位の 'svg' 要素にバージョンを追加 --> <xsl:template match="/svg:svg"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:attribute name="version">1.1</xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- 全ての 'rect' 要素にスタイル付けを追加 --> <xsl:template match="svg:rect"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:attribute name="fill">red</xsl:attribute> <xsl:attribute name="stroke">blue</xsl:attribute> <xsl:attribute name="stroke-width">3</xsl:attribute> </xsl:copy> </xsl:template> </xsl:stylesheet> mystyle.xsl により変換される SVG ファイル <?xml version="1.0" standalone="no"?> <svg width="10cm" height="5cm" xmlns="http://www.w3.org/2000/svg"> <rect x="2cm" y="1cm" width="6cm" height="3cm"/> </svg> mystyle.xsl が適用された後の SVG 内容 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="10cm" height="5cm" version="1.1" xmlns="http://www.w3.org/2000/svg"> <rect x="2cm" y="1cm" width="6cm" height="3cm" fill="red" stroke="blue" stroke-width="3"/> </svg>
CSS をサポートする SVG の実装においては、以下をサポートすることが要求される:
SVG implementations that support CSS are required to support the following:
次の例に全ての矩形に対し 'fill' および 'stroke' プロパティをそれぞれ赤色と青色に設定する外部 CSS スタイルシートの利用を示す:
The following example shows the use of an external CSS style sheet to set the 'fill' and 'stroke' properties on all rectangles to red and blue, respectively:
mystyle.css rect { fill: red; stroke: blue; stroke-width: 3 } mystyle.css を参照する SVG ファイル <?xml version="1.0" standalone="no"?> <?xml-stylesheet href="mystyle.css" type="text/css"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="10cm" height="5cm" viewBox="0 0 1000 500" xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect x="200" y="100" width="600" height="300"/> </svg>
CSS スタイルシートを 'style' 要素内に記述することにより SVG 内容に埋めこむことができる。前の例と同じ結果を得る内部 CSS スタイルシートを次の例に示す:
CSS style sheets can be embedded within SVG content inside of a 'style' element. The following example uses an internal CSS style sheet to achieve the same result as the previous example:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="10cm" height="5cm" viewBox="0 0 1000 500" xmlns="http://www.w3.org/2000/svg" version="1.1"> <defs> <style type="text/css"><![CDATA[ rect { fill: red; stroke: blue; stroke-width: 3 } ]]></style> </defs> <rect x="200" y="100" width="600" height="300"/> </svg>
CSS スタイルシートを
CDATA
ブロック(<![CDATA[ ... ]]>
)の中に置いていることに注意。 CDATA
ブロック内に内部スタイルシートを置くことはときに必要になる。 XML パーサが誤認する ">" のような文字を含ませられるからである。 XML パーサに誤認されるような文字が使われていなくとも、内部スタイルシートを CDATA
ブロックに置くことは強く推奨される。
Note how the CSS style sheet is placed within a
CDATA
construct (i.e., <![CDATA[ ... ]]>
). Placing internal CSS style sheets within CDATA
blocks is sometimes necessary since CSS style sheets can include characters, such as ">", which conflict with XML parsers. Even if a given style sheet does not use characters that conflict with XML parsing, it is highly recommended that internal style sheets be placed inside CDATA
blocks.
CSS をサポートする実装には CSS インラインスタイルのサポートも要求される。 HTML の style 属性と同様に、 CSS インラインスタイルは SVG の style 属性内でセミコロンで区切られた "name : value" 形式のプロパティ宣言のリストとして記述される。
Implementations that support CSS are also required to support CSS inline style. Similar to the style attribute in HTML, CSS inline style can be declared within a style attribute in SVG by specifying a semicolon-separated list of property declarations, where each property declaration has the form "name: value".
次の例では style 属性を利用して矩形に対して 'fill' および 'stroke' プロパティをあてがう方法が示されている。前の例と同様、矩形は内部を赤色に、外形線を青色に塗られる:
The following example shows how the 'fill' and 'stroke' properties can be assigned to a rectangle using the style attribute. Just like the previous example, the rectangle will be filled with red and outlined with blue:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="10cm" height="5cm" viewBox="0 0 1000 500" xmlns="http://www.w3.org/2000/svg" version="1.1"> <rect x="200" y="100" width="600" height="300" style="fill:red; stroke:blue; stroke-width:3"/> </svg>
CSS スタイルシートをサポートするUAは、次に挙げる [CSS2] の機能がサポートされていなければならない。
In an SVG user agent that supports CSS style sheets, the following facilities from [ CSS2 ] must be supported:
CDATA
ブロックとして埋めこまれている CSS スタイルシート。
CDATA
block.
CSS によりスタイル付けされる SVG 内容に ICC カラープロファイルも適用できるようにするため、 SVG ではカラープロファイルを定義するための@規則( at-rule ) [CSS2-ATRULES] として @color-profile が定義される。
SVG defines an @color-profile at-rule [ CSS2-ATRULES ] for defining color profiles so that ICC color profiles can be applied to CSS-styled SVG content.
相対 URI と外部 CSS スタイルシートについての注意: CSS2 仕様 [CSS-URI] によれば、スタイルシート内の相対 URI ( [RFC2396] )はスタイルシートの基底 URI を基に解決されるのであって、参照する文書の基底 URI を基にするのではない。
Note the following about relative URIs and external CSS style sheets: The CSS2 specification [ CSS-URI ] says that relative URIs (as defined in [ RFC2396 ]) within style sheets are resolved such that the base URI is that of the style sheet, not that of the referencing document.
プレゼンテーション属性 によるプロパティ宣言は XML [XML10] で記述され、大文字と小文字が区別される。一方で、 CSS スタイルシートまたは style 属性内で指定される CSS プロパティ宣言は一般的に少数の例外を除いて文字の大小が区別がされない( CSS2 仕様 4.1.3 Characters and case を参照)。
Property declarations via presentation attributes are expressed in XML [ XML10 ], which is case-sensitive. CSS property declarations specified either in CSS style sheets or in a style attribute, on the other hand, are generally case-insensitive with some exceptions (see section 4.1.3 Characters and case in the CSS2 specification).
プレゼンテーション属性は XML 属性として記述されるので、文字の大小が区別され、上記
「プレゼンテーション属性の実体定義」
で挙げられている名前と完全に一致していなければならない。プレゼンテーション属性を
'fill'
プロパティの値の指定に用いるならば、属性名は 'fill' でなければならず、'FILL' や 'Fill' は不可である。font-style="italic"
内の "italic" のようなキーワード値の文字の大小も区別され、仕様で定められているものと全く同じ文字の大小でなければならない。例えばキーワード "sRGB" では "s" は小文字、"RGB" は大文字でなければならない。
Because presentation attributes are expressed as XML attributes, presentation attributes are case-sensitive and must match the exact name as listed under
"Entity definitions for the presentation attributes"
, above. When using a presentation attribute to specify a value for the
'fill'
property, the presentation attribute must be specified as 'fill' and not 'FILL' or 'Fill'. Keyword values, such as "italic" in font-style="italic"
, are also case-sensitive and must be specified using the exact case used in the specification which defines the given keyword. For example, the keyword "sRGB" must have lowercase "s" and uppercase "RGB".
CSS スタイルシート内や style 属性内でのプロパティ宣言は CSS 規則に従うので、文字の大小に関しては概してゆるやかである。しかしながら、スタイル付けプロパティを表現する異なった方法間における一貫性を促すため、文書作成者はこの CSS の利便性に頼らず、関連仕様で定義されている厳密なプロパティ名(通常は小文字とハイフンのみ)とプレゼンテーション属性に使用されているものと同一の文字の大小の並びによるキーワードを使用することが強く推奨される。
Property declarations within CSS style sheets or in a style attribute must only conform to CSS rules, which are generally more lenient with regard to case sensitivity. However, to promote consistency across the different ways for expressing styling properties, it is strongly recommended that authors use the exact property names (usually, lowercase letters and hyphens) as defined in the relevant specification and express all keywords using the same case as is required by presentation attributes and not take advantage of CSS's ability to ignore case.
SVG は CSS と XSL で共通の様々な関連するプロパティと手法、加えて多くの処理規則の意味内容を共有する。
SVG shares various relevant properties and approaches common to CSS and XSL, plus the semantics of many of the processing rules.
SVG は以下の機能を CSS と XSL とで共有する:
SVG shares the following facilities with CSS and XSL:
外部スタイルシートは "Associating Style Sheets with XML documents Version 1.0" [XML-SS] で述べられている仕組を利用して参照される。
External style sheets are referenced using the mechanism documented in "Associating Style Sheets with XML documents Version 1.0" [ XML-SS ].
スタイルシートは 'style' 要素を用いて SVG 内容に直接埋めこむことができる。 SVG の 'style' 要素は対応する HTML の要素と同一の属性を持っている( HTML の 'style' 要素 参照)
The 'style' element allows style sheets to be embedded directly within SVG content. SVG's 'style' element has the same attributes as the corresponding element in HTML (see HTML's 'style' element ).
<!ENTITY % SVG.style.extra.content "" > <!ENTITY % SVG.style.element "INCLUDE" > <![%SVG.style.element;[ <!ENTITY % SVG.style.content "( #PCDATA %SVG.style.extra.content; )*" > <!ELEMENT %SVG.style.qname; %SVG.style.content; > <!-- end of SVG.style.element -->]]> <!ENTITY % SVG.style.attlist "INCLUDE" > <![%SVG.style.attlist;[ <!ATTLIST %SVG.style.qname; xml:space ( preserve ) #FIXED 'preserve' %SVG.Core.attrib; type %ContentType.datatype; |
属性定義:
Attribute definitions:
スタイルデータの構文はスタイルシート言語に基づく。
The syntax of style data depends on the style sheet language.
いくつかのスタイルシート言語では style 属性内より 'style' 要素内でより広範囲の規則が許されている。例えば CSS の場合、規則の宣言は 'style' 要素内では許されているが style 属性では許されていない。
Some style sheet languages might allow a wider variety of rules in the 'style' element than in the style attribute. For example, with CSS, rules can be declared within a 'style' element that cannot be declared within a style attribute.
'style' 要素の例が上に示されている( 例 を見よ)。
An example showing the 'style' element is provided above (see example ).
属性定義:
Attribute definitions:
class 属性は一つ以上のクラス名を要素に指定する。要素はこれらのクラスに属すると言ってもよい。複数の要素インスタンスが同じクラス名を共有しても良い。クラス属性にはいくつかの役割がある:
The class attribute assigns one or more class names to an element. The element may be said to belong to these classes. A class name may be shared by several element instances. The class attribute has several roles:
以下は文書のメッセージをマークアップする目的で 'text' 要素を class 属性に関連して利用する例である。メッセージは英語とフランス語の両方で表示される。
In the following example, the 'text' element is used in conjunction with the class attribute to markup document messages. Messages appear in both English and French versions.
<!-- 英語メッセージ --> <text class="info" lang="en">Variable declared twice</text> <text class="warning" lang="en">Undeclared variable</text> <text class="error" lang="en">Bad syntax for variable name</text> <!-- フランス語メッセージ --> <text class="info" lang="fr">Variable déclarée deux fois</text> <text class="warning" lang="fr">Variable indéfinie</text> <text class="error" lang="fr">Erreur de syntaxe pour variable</text>
CSS スタイル付け をサポートする SVG-UAの場合、以下のスタイル規則により "info" メッセージは緑色に, "warning" メッセージは黄色に, "error" メッセージは赤色に表示される:
In an SVG user agent that supports CSS styling , the following CSS style rules would tell visual user agents to display informational messages in green, warning messages in yellow, and error messages in red:
text.info { color: green } text.warning { color: yellow } text.error { color: red }
style 属性は要素ごとのスタイル規則の指定を可能にする。 CSS によるスタイル付けが利用されている場合、要素の style 属性にセミコロンで区切られた "名前 : 値" 形式のプロパティ宣言を記述することにより、 CSS インラインスタイルを指定することができる。
The style attribute allows per-element style rules to be specified directly on a given element. When CSS styling is used, CSS inline style is specified by including semicolon-separated property declarations of the form "name : value" within the style attribute
属性定義:
Attribute definitions:
スタイル属性は個々の SVG 要素ごとに指定してよい。同じスタイルがいくつもの要素で利用されている場合、文書作成者は 'style' 要素を利用して情報を再編成すべきである。最適な柔軟性を得るためには、文書作成者は外部スタイルシートを作成すべきである。
The style attribute may be used to apply a particular style to an individual SVG element. If the style will be reused for several elements, authors should use the 'style' element to regroup that information. For optimal flexibility, authors should define styles in external style sheets.
style 属性の例は上に示されている( 例 を見よ)。
An example showing the style attribute is provided above (see example ).
'svg' 要素の contentStyleType 属性は文書片において既定のものとなるスタイルシート言語を指定する。
The contentStyleType attribute on the 'svg' element specifies the default style sheet language for the given document fragment.
UAが CSS をサポートしていようといまいと、 SVG におけるプロパティの継承は CSS2 仕様で定義されたプロパティ継承規則に従う。プロパティ継承の正式な定義は CSS2 仕様 6.2 節「継承」で述べられている( Inheritance 参照)。
Whether or not the user agent supports CSS, property inheritance in SVG follows the property inheritance rules defined in the CSS2 specification. The normative definition for property inheritance is section 6.2 of the CSS2 specification (see Inheritance ).
プロパティが親の値を継承できるかどうかは各プロパティの定義に示されている。
The definition of each property indicates whether the property can inherit the value of its parent.
SVG では CSS2 と同様、ほとんどの要素は計算値( computed value ) [ CSS2-COMPUTED] を継承する。計算値以外の何かが継承される場合については、プロパティ定義が規則を定める。利用単位, 画素単位(例えば "20px" ), 絶対値 [ CSS2-COMPUTED] により指定された値 [ CSS2-SPECIFIED] の場合、計算値はその値に等しい。一定の相対的な単位により指定された値(即ち em, ex, パーセント)の場合、計算値はその単位が比較対象とする値の単位を持つ。したがって、親要素の 'font-size' が "10pt" で現在の要素の 'font-size' が "120%" ならば、その計算値は "12pt" となる。比較対象の値にいかなる SVG 標準の単位(即ち CSS 単位あるいは利用単位)も指定されていない場合(例えばパーセントが現在のビューポートやオブジェクトの包含ボックスに対して指定されているようなとき)、計算値は利用単位となる。
In SVG, as in CSS2, most elements inherit computed values [ CSS2-COMPUTED ]. For cases where something other than computed values are inherited, the property definition will describe the inheritance rules. For specified values [ CSS2-SPECIFIED ] which are expressed in user units, in pixels (e.g., "20px") or in absolute values [ CSS2-COMPUTED ], the computed value equals the specified value. For specified values which use certain relative units (i.e., em, ex and percentages), the computed value will have the same units as the value to which it is relative. Thus, if the parent element has a 'font-size' of "10pt" and the current element has a 'font-size' of "120%", then the computed value for 'font-size' on the current element will be "12pt". In cases where the referenced value for relative units is not expressed in any of the standard SVG units (i.e., CSS units or user units), such as when a percentage is used relative to the current viewport or an object bounding box, then the computed value will be in user units.
注意: SVG に備わっている特質として、要素のプロパティに祖先要素と異なる値があてがわれているにもかかわらず祖先にあてがわれたプロパティが影響することがある。例えば祖先要素に 'clip-path' (クリッピングパス)プロパティが指定されているとき、その子孫において 'clip-path' プロパティの値が 'none' に指定されていても、祖先のクリッピングパスが子孫に適用される。何故なら SVG の意味内容に基づけば、与えられた要素に適用されるクリッピングパスは要素自身とその祖先要素すべてに指定されたクリッピングパスの共通部分になるからである。ここで重要な考え方は、プロパティ値の割当てが(プロパティ継承も含めて)最初になされるということである。各要素のプロパティに値があてがわれた後、UAは各プロパティの意味内容を適用する。その結果として祖先要素にあてがわれたプロパティが子孫の描画に影響することが起こり得る。
Note that SVG has some facilities wherein a property which is specified on an ancestor element might effect its descendant element, even if the descendant element has a different assigned value for that property. For example, if a 'clip-path' property is specified on an ancestor element, and the current element has a 'clip-path' of 'none' , the ancestor's clipping path still applies to the current element because the semantics of SVG state that the clipping path used on a given element is the intersection of all clipping paths specified on itself and all ancestor elements. The key concept is that property assignment (with possible property inheritance) happens first. After properties values have been assigned to the various elements, then the user agent applies the semantics of each assigned property, which might result in the property assignment of an ancestor element affecting the rendering of its descendants.
スタイルシートの可視/有効範囲は以下で定義される:
The following define the scope/range of style sheets:
UAは SVG 名前空間の要素に適用される視覚メディア [ CSS2-VISUAL] 用のUAスタイルシート [CSS2-CASCADE-RULES] を維持管理することになる。下のUAスタイルシートは CSS の構文で記述されている。しかしながら、たとえUAが CSS スタイルシートをサポートしていなくても、この既定のスタイルシートに基づく振る舞いをサポートすることが要求される:
The user agent shall maintain a user agent style sheet [ CSS2-CASCADE-RULES ] for elements in the SVG namespace for visual media [ CSS2-VISUAL ]. The user agent style sheet below is expressed using CSS syntax; however, user agents are required to support the behavior that corresponds to this default style sheet even if CSS style sheets are not supported in the user agent:
svg, symbol, image, marker, pattern, foreignObject { overflow: hidden } svg { width:attr(width); height:attr(height) }
上記UAスタイルシートの最初の行は、列挙された要素に対し新しい 初期クリッピングパス を 初期ビューポート の境界に確立することを指示している。これらの要素は 新しいビューポートを確立する要素 である。(詳細は SVG における 'overflow' プロパティの利用についての記述を見よ。)
The first line of the above user agent style sheet will cause the initial clipping path to be established at the bounds of the initial viewport . Furthermore, it will cause new clipping paths to be established at the bounds of the listed elements, all of which are elements that establish a new viewport . (Refer to the description of SVG's use of the 'overflow' property for more information.)
上記UAスタイルシートにおける二行目は 'svg' 要素の width および height 属性を CSS2 によるレイアウト [CSS2-LAYOUT] の過程において CSS2 の 'width' および 'height' プロパティの既定値にすることを指示している。
The second line of the above user agent style sheet will cause the width and height attributes on the 'svg' element to be used as the default values for the 'width' and 'height' properties during [ CSS2-LAYOUT ].
聴覚メディアの目的のため、 SVG はスタイル付け可能な XML 文法を表現する。 CSS 聴覚スタイルシートをサポートするUAでは聴覚スタイルプロパティ [CSS2-AURAL] を [CSS2] で定められたようにして適用できる。
For the purposes of aural media, SVG represents a stylable XML grammar. In user agents that support CSS aural style sheets, aural style properties [ CSS2-AURAL ] can be applied as defined in [ CSS2 ].
聴覚スタイルプロパティは文字データを内容に持つ任意の SVG 要素に適用できる。以下の要素が含まれる: 'desc', 'title, 'tspan', 'tref', 'altGlyph', 'textPath' 。聴覚スタイルシートをサポートするUAでは以下の [CSS2] プロパティを適用できる:
Aural style properties can be applied to any SVG element that can contain character data content, including 'desc', 'title, 'tspan'. 'tref'. 'altGlyph' and 'textPath'. On user agents that support aural style sheets, the following [CSS2] properties can be applied:
聴覚スタイルシートに加えて、
[DOM2]
をサポートするUAには
[DOM2-CSS]
で定義された DOM インターフェースのうち聴覚プロパティ
[CSS2-AURAL]
に対応する部分をサポートすることが要求される。(
DOM2 CSS オブジェクトモデルとの関係
を見よ)
For user agents that support aural style sheets and also support
[DOM2]
, the user agent is required to support the DOM interfaces defined in
[DOM2-CSS]
that correspond to aural プロパティ s
[CSS2-AURAL]
. (See
Relationship with DOM2 CSS object model
.)
要素 | 属性 | 内容モデル |
---|---|---|
style | Core.attrib, type, media, title | (#PCDATA) |
Style モジュールは Style.attrib 属性セットを定義する。
コレクション名 | コレクションに含まれる属性 |
---|---|
Style.attrib | style, class |
次に挙げるインターフェースが以下で定義される: SVGStyleElement
SVGStyleElement インターフェースは 'style' 要素に対応する。
interface SVGStyleElement : SVGElement { attribute DOMString xmlspace; // raises DOMException on setting attribute DOMString type; // raises DOMException on setting attribute DOMString media; // raises DOMException on setting attribute DOMString title; // raises DOMException on setting };
DOMException |
NO_MODIFICATION_ALLOWED_ERR :読み出し専用の属性値の変更を試みたときにレイズされる。
|
DOMException |
NO_MODIFICATION_ALLOWED_ERR :読み出し専用の属性値の変更を試みたときにレイズされる。
|
DOMException |
NO_MODIFICATION_ALLOWED_ERR :読み出し専用の属性値の変更を試みたときにレイズされる。
|
DOMException |
NO_MODIFICATION_ALLOWED_ERR :読み出し専用の属性値の変更を試みたときにレイズされる。
|