HTML attributes, inline styles or style rules #2
By glazou on Friday 26 September 2008, 13:19 - Mozilla - Permalink
Given a change on an HTML element based on an HTML attribute:
- if the HTML attribute change has an equivalence in CSS style rules:
- determine the selector(s) and the corresponding declarations for that change
- in all editable stylesheets (embedded or remote from an "editable" domain) applied to the current medium, find all rules based on these selectors and nix the corresponding declarations if present ; remove rules if empty after that change
- if there's no editable stylesheet, create one
- for each selector, try to find a remaining rule for that selector ; if there's no rule, create a new one
- attach the corresponding declarations to that new rule
- get the computed style for the element and check if it corresponds to the desired style
- if it does, then leave as is
- if it does not, then a rule of higher precedence in the cascade masks the ones we just created
- if the rules we just created can be contained in inline styles on the element, then nix the rules and turn the corresponding styles into a style attribute on the element
- if they can't be contained in inline styles, then we're doomed; we have only two choices : let as is but the visual result is different fom user's expectations and that is A Bad Thing ; nix the rules and fallback to the HTML attribute...
- if there's no CSS equivalence, apply the HTML attribute
Hum, to say the least. Coments anyone ?
Comments
First I assume that we know wether the page use strict Html or transitionnal.
Setup a configuration attribute to let the user choose the heuristic of the algorithm with those settings (non limitative list):
- "as much CSS as you can, and HTML attribute if it fails"
- "as much CSS as you can, and warn me that my request could not be fulfilled, I will fix it by hand during this session"
- "as much CSS as you can, if it is not possible then just give up, I don't care."