SVG: Use Attributes or CSS to style?

前端 未结 4 1669
无人共我
无人共我 2021-02-04 02:09

In HTML it is recommended to seperate Content from Style, thus you should create external CSS-Files for your styles. As I am just getting started with SVG I now wonder: Does thi

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 02:41

    I arrived here because I was trying to remember whether attributes or styles have greater precedence. This is one practical reason why you'd want one over another.

    Attributes get applied as "presentation hints", as if they were the first of the cascading style sheets. In other words, this gives them lowest precedence.

    Thus the precedence, from lowest to highest, is

    1. attributes
    2. CSS style sheets
    3. inline styles

    It's a little confusing that an inline style has much greater precedence than the attribute it's next to. (I keep having to look this up!)

    There aren't going to be any new presentation attributes, and we are encouraged to use CSS styling instead, but it doesn't sound like presentation attributes are going away anytime soon.

    More detail can be found in the Presentation Attributes section of the Styling chapter of the SVG standard.

提交回复
热议问题