Why can't I select elements by their href-attribute?
CSS
/* Works */
svg image[type=overlay]{
outline: 3px solid blue;
}
/* Doesn't work */
svg image[href*='temp']{
outline: 5px solid red;
}
/* Doesn't work either */
svg image[href='wcs/WFL/position/temp2.png']{
outline: 5px solid red;
}
SVG
<image display="inline" type="overlay" width="148" height="90" x="920" y="918" transform="" href="wcs/WFL/position/temp2.png"><title>B02003
Temp: 2</title></image>
I did notice the browsers turns the href attribute to xlink:href
but image[xlink:href*='temp']
doesn't work either.
How can I make this work?
Edit: The SVG uses the following namespaces, I think this causes the problem but I don't know how to get around it.
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
Fiddle
use. For <use> , href defines a URL referring to an element or fragment within an SVG document to be cloned. The <use> element can reference an entire SVG document by specifying an href value without a fragment.
The [attribute|="value"] selector is used to select elements with the specified attribute, whose value can be exactly the specified value, or the specified value followed by a hyphen (-). Note: The value has to be a whole word, either alone, like class="top", or followed by a hyphen( - ), like class="top-text".
The [attribute~=value] selector is used to select elements with an attribute value containing a specified word.
Firstly, in order to use xlink
slectors, you need to to declare the xlink
namespace at the top of your stylesheet according to the spec:
@namespace xlink 'http://www.w3.org/1999/xlink';
Then, you can use the following attribute selector with a namespace prefix:
svg image[xlink|href*="temp"] {
outline: 3px solid red;
}
The attribute name in an attribute selector is given as a CSS qualified name: a namespace prefix that has been previously declared may be prepended to the attribute name separated by the namespace separator "vertical bar" (|). In keeping with the Namespaces in the XML recommendation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With