jonkemp/inline-css

Selector specificity not working for !important rules

Open

#32 geöffnet am 14. März 2016

Auf GitHub ansehen
 (8 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (80 Forks)github user discovery
enhancementhelp wanted

Repository-Metriken

Stars
 (440 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

When two selectors match the same element, and both have !important, then the selector specificity is ignored and the last rule wins:

inlineCss('<style>p a {color: red!important} a{color: black!important}</style>  <p><a>test', {url: '/'}).then(s=>console.log(s))
// '<p><a style="color: black;">test</a></p>'
inlineCss('<style>a{color: black!important} p a {color: red!important}</style>  <p><a>test', {url: '/'}).then(s=>console.log(s))
// '<p><a style="color: red;">test</a></p>'

However for the browsers it’s different. No matter which rule goes first, if both have !important in them, the more specific wins.

Contributor Guide