For example, I'd like to do something like the following:
.myRedPath {
fillcolor: red;
}
...
<v:path class="myRedPath" v="..."/>
to fill my paths with a red color. Is this possible with the color and opacity of the fill and stroke attributes for VML elements? If so, how?
As mentioned in other answers, you may use DHMTL behaviors to apply any style specified in your style sheet to your VML element as behaviors are supported from IE5 to IE9.
Start by creating a HTC file, eg: vmlcss.htc:
Then apply it to your VML elements. For your particular example, you would use:
Finally, specify the styles as shown in your example:
You may want to modify the behavior file to add support for all VML attributes.
One could use such a technique to write a library that draws shapes using VML or SVG (depending on the browser support) and allows styling through CSS. Support for SVG styles could then be added to the VML objects using such a behavior file by mapping each SVG style to the corresponding VML attributes.
In IE7, you can do following:
But it doesn't work in IE8+ Standards mode, so not really that much useful.
VML uses attributes instead of CSS properties, so the only way to reference them in a style sheet is to add another behavior URL which references a htc which sets attribute values. Otherwise, use a HTML element to wrap the VML element and add the background color to it: