The SVG document
in Listing 2.9 uses an internal stylesheet in order to define the colors of a pair of nested rectangles as
Listing 2.9 style2.svg
|
|
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd"> <svg width="800" height="500"> <style type="text/css"> <![CDATA[ rect { stroke-width:4; stroke:blue; fill:red; } ]]> </style> <rect x="50" y="50" width="200" height="200"/> <rect x="100" y="100" width="100" height="100"/> </svg>
|
|
The stylesheet definition in Listing 2.9 is embedded in a CDATA section, which starts with the following lines:
<style type="text/css"> <![CDATA[
The first line declares that the style is of type
text/css
, which means that what will follow consists of CSS (Cascading Style Sheet) rules. The second line contains the string
CDATA
, which refers to 'character data,' and it
]]> </style>
Now let's look at the contents of the stylesheet given in the following fragment:
rect { stroke-width:4; stroke:blue; fill:red; }
The attributes above are simply
The SVG document in Listing 2.10 uses an external stylesheet in order to render a pair of nested rectangles as listed in Figure 2.6.
Listing 2.10 style3.svg
|
|
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd"> <?xml-stylesheet type="text/css" href="externalStyle1.css" ?> <svg width="800" height="500"> <rect x="50" y="50" width="200" height="200"/> <rect x="100" y="100" width="100" height="100"/> </svg>
|
|
Listing 2.11 contains three SVG style-
Listing 2.11 externalStyle1.svg
|
|
rect { stroke-width:4; stroke:blue; fill:red; }
|
|
The external stylesheet in Listing 2.11 contains the same information as the internal stylesheet in Listing 2.9. You can specify attribute