Consider the CSS selection I have here:
/* This works:
#myChart .ct-series-b .ct-bar {
*/
/* This does not (chromium, glnxa64) */
['ct\:series-name'='second'] .ct-bar {
/* Colour of your points */
stroke: black;
/* Size of your points */
stroke-width: 20px;
/* Make your points appear as squares */
stroke-linecap: round;
}
This is a sample chart using https://gionkunz.github.io/chartist-js/
I am trying to select the ct-bar elements:
The colon appears to be throwing off the selector. I have tried various escape approaches :, \3A with a space after, single and double quotes - no luck.
I've never used Chartist, but judging by the
ct:
namespace prefix, it appears to be an extension to SVG markup. So you're no longer really dealing with HTML here; you're dealing with XML, because SVG is an XML-based markup language.Escaping the colon or otherwise specifying it as part of the attribute name doesn't work because the
ct:
no longer becomes part of the attribute name when it's treated like a namespace prefix (which is what it is). In a regular HTML document, an attribute name likect:series-name
would indeed include the prefix, because namespace prefixes only have special meaning in XML, not in HTML.Anyway, the web inspector shows the following XML for your
svg
start tag:What you need to do is reflect this XML namespace in your CSS using a
@namespace rule
:And, rather than escaping the colon, use a pipe to indicate a namespace prefix:
And it should work as expected.
You shouldn't quote the attribute name, otherwise you are correctly escaping the colon.
See https://msdn.microsoft.com/en-us/library/ms762307(v=vs.85).aspx
It seems like the namespace selector would work only when the namespace is defined within the CSS itself in the below format:
Once we add the namespace definition for
ct
into the CSS, the namespace based selector works as expected. The namespace's URI was taken from the<svg>
tag that was generated.Fiddle Demo.
Note: The below selector doesn't work even after the namespace definition is added. The reason for this is provided by BoltClock in his answer.