Forum Moderators: not2easy
4. XML namespaces
XML namespaces are referred to in both the CSS3 namespaces module and the CCS3 selectors module.
CSS3 adds supports for XML namespaces. If you check an xhtml <html> tag, you'll notice:
xmlns="http://www.w3.org/1999/xhtml" as an attribute in there. The "URI" in there is just an identifier, and allows you can link the namespace in CSS with the one in the document(s) you are styling. There are two parts to it: declaring the namespaces (linking a name and the URI) using an @rule, and selectors that allow references to the namespaces.
Syntax: @namespace "URI"
Declares the default namespace
Syntax: @namespace prefix "URI"
Delares a prefix to apply a certain namespace.
Example:
@namespace "http://www.w3.org/1999/xhtml";
@namespace svg "http://www.w3.org/2000/svg";
Declares the xhtml namespace as the default and creates a prefix svg that applies the svg namespace.
Syntax: prefix¦E
Syntax: ¦E
Syntax: *¦E
Syntax: E
Example:
A too simple example to use namespaces in order to share a stylesheet between a SVG and a xhtml document.
style.css:
@namespace "http://www.w3.org/1999/xhtml";
@namespace svg "http://www.w3.org/2000/svg";
svg¦rect {
fill: yellow;
stroke: blue;
stroke-width: 10;
}
div {
background-color: yellow;
}
file.svg:
<?xml version="1.0" standalone="no"?>
<?xml-stylesheet href="style.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>
file.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Namespace test</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div>
hello world!
</div>
</body>
</html>
Practical use
Allow to share a stylesheet between your SVG and xhtml and other xml documents ? It would be interesting to see the long term vision of what this is intended to be.
Support
Graceful fallback
IE is the troubled one in this, but it doesn't support standards like SVG anyway.
More info: