I am building charts with Raphael.js that have all sorts of styling attached to them, including different hover styling. The following works across browsers:
var bar = paper.rect(x, y, width, height)
.attr({"stroke-width": 0, fill: #baeadd; "fill-opacity": 0.3})
In an attempt to fully separate the appearance from the functionality, I am trying to target my Raphael elements with CSS and add all the styling from there.
I used the technique outlined here to be able to target my shapes in all browsers, using unique ID-s:
bar.node.id = "bar-" + id;
-
*[id^="bar"] {
// Attributes listed here seem to work in modern browsers
// http://raphaeljs.com/reference.html#Element.attr
fill: #baeadd;
fill-opacity: 0.3;
}
*[id^="bar"]:hover {
fill-opacity: 0.5;
}
The above does not work on IE8, where Raphael injects vml shape elements instead. I am able to specify standard CSS properties such as background-color
, and the shape element will get the styling fine, but I would like to know how to apply attributes such as fill-opacity
, stroke-width
, and the likes.
Is it possible to set fill and stroke colors and opacity on VML paths using CSS? explains the role of behavior: url(#default#VML)
. I can see that Raphael already adds a .rvml
class to all the shape elements it creates, and applies this behavior property, but it doesn't seem to take effect as soon as I stop applying attributes via JS and start specifying them in the CSS.