https://bugzilla.wikimedia.org/show_bug.cgi?id=61440

--- Comment #5 from Krinkle <[email protected]> ---
Note that !important must never be used. It is a valid bug for upstream
CSSJanus (since it's valid CSS), but should not bare any relevance to code in
Wikimedia environments.

There is not a single valid use case for using !important (with the exception
of working around upstream code running on the same page that also uses
!important, because only !important can trump !important).

Any other case, and I mean, *any* other case, has other solutions that are
better. Using !important breaks cascading nature and is simply unneeded
infectious overkill. Consider it similar to other bad coding patterns that
should be disallowed by convention (like using the @-operator in PHP, or loose
== comparison and automatic semi-colon insertion in JavaScript).

Using irrelevant selectors (as Ic5c575068d911 did) is not necessary. In most
cases it's  just unnecessary to begin with (e.g. unjustified paranoia). In
other cases it may be result of a bug elsewhere in the code.

To override a style, always use the same selector as the original style and
you'll be fine.

If your code is loaded before the other code, something is wrong. If that wrong
thing can't be fixed, try harder. Eventually, you may want to resort to one of
few workarounds, such as:
* Repeat the same selector to increase weight, like .foo.foo.foo.foo
  (however much weight you need), still leaves you in a better environment than
important by allowing multiple code paths to use the same technique and control
their weight.
* Add [class] selectors (less heavy).
* Use default elements as ancestor selector ("body .foo", "html body .foo").
Better than adding in random ancestors that are not relevant to your code. And
more maintainable as these don't change.

Anything but !important.

-- Krinkle

[1] 3.14 things you didn't know about CSS: http://vimeo.com/100264064

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to