W3C home > Mailing lists > Public > www-svg@w3.org > January 2014

Re: Precedence of CSS rules and presentation attributes in SVG

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Sun, 19 Jan 2014 20:32:57 -0800
Message-ID: <CAAWBYDCTpPvaUD0arpSMGPT_zUaJhBKrKNrQTHTkkmAaiaH_xg@mail.gmail.com>
To: Röthig, Prof. Dr. Jürgen <roethig@dhbw-karlsruhe.de>
Cc: "www-svg@w3.org" <www-svg@w3.org>
On Sat, Jan 18, 2014 at 10:44 AM, Röthig, Prof. Dr. Jürgen
<roethig@dhbw-karlsruhe.de> wrote:
> I understand why it was so in the beginning since CSS was to replace presentational attributes and tags of HTML 3.2. But for SVG, there is no need to replace the presentational attributes - they were introduced although CSS was already present and could and can be used with SVG up to now and probably in the future as well. Otherwise, the presentational attributes of SVG would need to be marked as deprecated, at least.
>
> And what's the use case of a presentation attribute in SVG? I would like to use CSS rules (from an external stylesheet) for global design issues (e.g. stroke width and color) for most elements, as long as the elements do not need to be specific. But in case I need a special design for a single element or just few elements, I might use the presentation attribute. And even more important, for that special single element, I might easily change the presentation with the help of JavaScript (e.g. due to some user interaction), whereas it is not at all trivial (and should not be done IMHO) to change a corresponding CSS rule with JavaScript ... well, of course, as a work around, I might use a special class for that special element (as long as it is "special"), or I might change its style attribute (!), but if there is more than one class or styling information given in the attribute, I would at least need to use regexp handling for this (to filter out the old information and replace it by the new one), and this is complex and not very efficiently implemented in most browsers ...
>
> What was the rationale behind that decision other than preceding old HTML presentation attributes and elements with CSS rules? And if there is none, would there be any chance to change that rule for SVG presentation attributes? Ah, I already hear those arguing "why should we have an exception for SVG in the CSS standard?", but I might reply that another exception for the same issue is already present in the spec of CSS2.1 regarding HTML itself (user agent level vs. author level, see quote above).

SVG and CSS have worked together for years, and the behavior of the
styling attributes can't be changed at this point - it would break too
many documents as they suddenly receive incorrect styling.

Using the style attribute to override global style is slightly less
convenient than using the other attributes when writing static SVG,
but they're approximately equally easy to use when scripting.

Based on your talk of using regexes, though, it sounds like you might
not be aware of the CSSOM APIs for manipulating CSS styles on an
element.  (Approximately here:
<http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-camel-cased-attribute>.)
 If you want to change a property, you absolutely do not need to do
string manipulation on the style attribute.  Instead, do something
like "el.style.stroke='black';".  There's no need to *ever* set the
style attribute directly, except in very rare cases.

~TJ
Received on Monday, 20 January 2014 04:33:44 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:54:50 UTC