Let's start with three simple facts — as Petr Pisar found out.
- The underscore ("_") is allowed in CSS identifiers by the CSS2.1 Specification
- Browsers have to ignore unknown CSS properties
- MSIE 5+ for Windows ignores the "_" at the beginning of any CSS property name
Therefore, a CSS definition, e. g. _color:red
is:
- Correct, for CSS 2.1 specification allows it (even if software validators, knowing only older version CSS 2.0, say it's a bug: they are wrong, it's correct).
- Ignored in any browser but WinIE
- Treated as
color:red
in WinIE
Thus, this IE's bug/feature is very simple and clear way to set CSS properties for WinIE only (MacIE doesn't have this bug/feature). It's easy to fix e. g. mis-implemented position:fixed
in WinIE (see the example).
Začněme se třemi prostými fakty — jak si jich všiml Petr Písař.
- Podtržítko ("_") je povoleno v identifikátorech CSS specifikací CSS2.1
- Prohlížeče musí ignorovat neznámé vlastnosti
- MSIE 5+ pro Windows ignoruje znak "_" na začátku názvu jakékoli vlastnosti
Tudíž definice CSS, např. _color:red
je:
- Korektní, protože specifikace CSS 2.1 ji povoluje (ať si softwarové validátory, které znají jen starší verzi CSS 2.0, říkají, co chtějí — v tom, že je to chyba, se mýlí).
- Ignorována v každém prohlížeči kromě WinIE
- Zpracována jako
color:red
v WinIE
Tato chyba/vlastnost IE je tak velmi jednoduchým a čistým způsobem, jak v CSS nastavit vlastnosti jen pro WinIE (MacIE tuto chybu/vlastnost nemá). Je třeba snadné opravit chybnou implementaci position:fixed
ve WinIE (viz příklad).