How to use CSS attribute selector for an SVG element with namespaced attribute href?

后端 未结 1 1457
野的像风
野的像风 2021-02-14 13:30

Why can\'t I select elements by their href-attribute?

CSS

/* Works */
svg image[type=overlay]{
    outline: 3px solid blue;
}

/* Doesn         


        
1条回答
  •  深忆病人
    2021-02-14 14:17

    Demo Fiddle

    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

    0 讨论(0)
提交回复
热议问题